在 android 中使用沉浸式全屏模式时为白色 space

White space when using Immersive Full-Screen Mode in android

我使用下面的代码来使用沉浸式全屏模式:

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 // hide nav bar
            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
            | View.SYSTEM_UI_FLAG_IMMERSIVE);

但是当我 运行 我的应用程序时,显示白色 space 而不是通知和底栏。

我想我的 XML 文件有误。 这是我的 XML 文件:

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#303030"
    tools:context="programsimple.game.FullscreenActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:fitsSystemWindows="true"
        android:background="#eeeeee">

        <ImageView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@drawable/background"/>

        <Button
            android:layout_width="110dp"
            android:layout_height="70dp"
            android:background="@drawable/button_shape"
            android:layout_centerVertical="true"
            android:id="@+id/btnStartGame"
            android:layout_centerHorizontal="true"
            android:text="شروع"
            android:textSize="25sp"
            android:textColor="#97d2ff"/>

    </RelativeLayout>

</FrameLayout>

有没有错误?

更新 : 我用 KitKat 测试。

白色是由于RelativeLayout中设置的背景。要删除底部的白色条,只需从 RelativeLayout:

中删除此标签
  android:fitsSystemWindows="true"

它在创建应用程序时添加,并向布局添加常规填充以确保内容不会与系统重叠windows。