我的片段在沉浸式粘滞模式下的布局有问题。系统栏和导航栏正在正确消失,但片段布局不会拉伸以填充这些栏以前占用的空间。
这是一张展示我所说内容的截图:
红色是活动的背景,蓝色是片段的背景。
下面是我如何启动沉浸式粘滞模式(在活动加载片段之前):

public void startImmersiveMode()
{
    getWindow().getDecorView().setSystemUiVisibility(
        View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN |
        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
        View.SYSTEM_UI_FLAG_FULLSCREEN |
        View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);
}

如何使片段扩展以覆盖活动?
编辑-以下是一些XML:
活动:
<FrameLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_container"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    android:background="@color/red"/>

碎片:
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/container_view"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_blue_bright"
    android:gravity="center">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Hello World"/>

</LinearLayout>

最佳答案

罪魁祸首是活动布局中的android:fitsSystemWindows="true"。我把它取下来之后,碎片扩大到占据了整个窗口。

07-24 09:47
查看更多