嵌入活动之间令人不快的分隔符

发布于 2024-10-20 17:43:53 字数 450 浏览 4 评论 0原文

我有一个 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 内的代码,用于获取子活动内容并添加它。

I have an ActivityGroup embeds some other activities. But at the top of each embedded activity layout there is a separator (with shadow, like 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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

停滞 2024-10-27 17:43:53

我发现这个问题 /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);
}

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);
}
囚我心虐我身 2024-10-27 17:43:53

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

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

它将有效地应用于所有嵌入的活动,并且它们将摆脱烦人的阴影。不幸的是,这消除了父 Activity 的影响,这可能不适合您的应用程序。

另一种方法是侵入视图层次结构以在运行时修改嵌入活动的相关属性。使用 HierarchyViewer 进行快速检查表明,这个恼人的阴影是作为 DecorView 内的 FrameLayout 的前景绘制的。 FrameLayout 本身包含我们实际的用户定义布局:

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

因此任务是在中间的这个 FrameLayout 上调用 setForeground(null)。如果我们修改 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!
        }
    }
}

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!
        }
    }
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文