我有一个 ActivityGroup 嵌入了一些其他 Activity 。但是在每个嵌入式 Activity 布局的顶部都有一个分隔符(带有阴影,如窗口自定义标题下方)。
我不知道如何删除它。
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 中的代码,用于获取子 Activity 内容并添加它。
最佳答案
我发现了这个问题 /getting-rid-of-the-gradient-at-the-top-of-an-activity-android但它不适用于嵌入式 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]:我做了一个小改动(虽然不是很好,但很管用)。
// 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) 替换。在父 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);
}
关于android - 嵌入式 Activity 之间令人不快的分隔符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5196521/