看起来所有嵌入式活动都从其父活动组继承其样式。因此,如果您将样式应用于没有 的活动组windowContentOverlay
,如下所示:
<style name="Theme.MasterActivity" parent="@android:style/Theme">
<item name="android:windowContentOverlay">@null</item>
</style>
它将有效地应用于所有嵌入式活动,它们将摆脱烦人的阴影。不幸的是,这会从父 Activity 中移除效果,这可能不适合您的应用。
另一种方法是侵入视图层次结构以在运行时修改嵌入活动的相关属性。使用 HierarchyViewer 快速检查显示,这个烦人的阴影被绘制FrameLayout
为DecorView
. 它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!
}
}
}