androidfullscreenandroid-immersive

White space when using Immersive Full-Screen Mode in android


I use below code to use Immersive Full-Screen Mode:

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);

But when I run my app, a white space shows instead of notification and bottom bar.

I think I have a mistake in my XML file. Here is my XML file:

<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>

Does it have any mistake?

update : I test with KitKat.


Solution

  • The white color is due to the background set in the RelativeLayout. To remove the bottom white bar, simply remove this tag from RelativeLayout:

      android:fitsSystemWindows="true"
    

    It gets added when the app is created and adds a general padding to the layout to ensure that contents don't overlap the system windows.