1

我有一个 ActivityGroup 嵌入了一些其他活动。但是在每个嵌入式活动布局的顶部都有一个分隔符(带有阴影,如窗口自定义标题下方)。

我不知道如何删除它。

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);
}

这是 ActivityGroup 内的代码,用于获取子活动内容并添加它。

4

2 回答 2

1

我发现了这个问题/getting-rid-of-the-gradient-at-the-top-of-an-activity-android但它不适用于嵌入式活动。

<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" />

[编辑]:我做了一个小技巧(它不是很好,但它有效)。

// 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);
    ...
}

每个 Activity.findViewById(id) 都会被 mGlobalWrapper.findViewById(id) 替换。在父活动中:

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);
}
于 2011-03-07T17:26:29.600 回答
0

看起来所有嵌入式活动都从其父活动组继承其样式。因此,如果您将样式应用于没有 的活动组windowContentOverlay,如下所示:

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

它将有效地应用于所有嵌入式活动,它们将摆脱烦人的阴影。不幸的是,这会从父 Activity 中移除效果,这可能不适合您的应用。

另一种方法是侵入视图层次结构以在运行时修改嵌入活动的相关属性。使用 HierarchyViewer 快速检查显示,这个烦人的阴影被绘制FrameLayoutDecorView. 它FrameLayout本身包含我们实际的用户定义布局:

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

所以任务是在中间调用setForeground(null)这个。FrameLayout如果我们重写 luc 的最后一个例子,它会是这样的:

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!
        }
    }
}
于 2011-04-12T13:43:55.080 回答