开发者

unpleasant separator between embedded activities

I have an ActivityGroup embeds some other activities. But at the top of each embedded activity layout there is a separator (with shadow, li开发者_如何转开发ke below a window custom title).

I don't know how to remove it.

Intent intent = new Intent(this, HomeLocalProductsActivity.class);
Window w = getLocalActivityManager().startActivity("LocalProducts", intent);
View dv = null == w ? null : w.getDecorView();
if (null != dv) {
    ((ViewGroup) findViewById(R.id.home_content_wrapper)).addView(dv);
}

This the code inside the ActivityGroup to get the sub-activity content and add it.


I found this question /getting-rid-of-the-gradient-at-the-top-of-an-activity-android but it doesn't work for embedded activity.

<style name="Theme.EmbeddedActivity" parent="@android:style/Theme">
    <item name="android:windowNoTitle">true</item>
    <item name="android:windowContentOverlay">@null</item>
</style>

<activity android:name="HomeLocalProductsActivity" android:theme="@style/Theme.EmbeddedActivity" />

[edit] : I made a small hack (it's not very nice but it works).

// values/ids.xml
<resources>
    <item type="id" name="embeddedcontent" />
    ...
</resources>

// layout/home_localproducts.xml
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@id/embeddedcontent">
    ...
</RelativeLayout>

// Embedded Activity
private ViewGroup mGlobalWrapper;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
    setContentView(R.layout.home_localproducts);
    mGlobalWrapper = (ViewGroup) findViewById(R.id.embeddedcontent);
    ...
}

Every Activity.findViewById(id) will be replaced by mGlobalWrapper.findViewById(id). And in the parent activity :

final Window w = getLocalActivityManager().startActivity("LocalProducts", intent);
final View dv = null == w ? null : w.getDecorView();
if (null != dv) {
    View content = dv.findViewById(R.id.embeddedcontent);
    ((ViewGroup) content.getParent()).removeView(content);
    wrapper.addView(content, 1);
    wrapper.setVisibility(View.VISIBLE);
}


It looks like all embeded activities inherit their style from their parent activity group. So, if you apply a style to the activity group that has no windowContentOverlay, like this:

<style name="Theme.MasterActivity" parent="@android:style/Theme">
    <item name="android:windowContentOverlay">@null</item>
</style>

It will effectively apply to all embeded activities and they'll get rid of the annoying shadow. Unfortunately, this removes the effect from the parent activity, which may not good look for your app.

Another approach is to hack into the view hierarchy to modify the relevent property of the embeded activities at runtime. A quick inspection with the HierarchyViewer shows that this annoying shadow is drawn as a foreground of a FrameLayout inside the DecorView. The FrameLayout itself contains our actual user-defined layout:

+-----------+     +-------------+     +--------------------+
| DecorView |-----| FrameLayout |-----| Your actual layout |----- ...
+-----------+     +-------------+     +--------------------+

So the task is to call setForeground(null) on this FrameLayout in the middle. If we rework the last example by luc, it will look like this:

final Window w = getLocalActivityManager().startActivity("LocalProducts", intent);
final View dv = null == w ? null : w.getDecorView();
if (dv != null && instanceof ViewGroup) {
    ViewGroup group = (ViewGroup) currentView;
    if (group.getChildCount() > 0) {
        View child = group.getChildAt(0);
        if (child instanceof FrameLayout) {
            ((FrameLayout) child).setForeground(null); // die, annoying shadow!
        }
    }
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜