amlwin
amlwin

Reputation: 4329

Status Bar is white when entering immersive full screen mode

I make a simple projet about immersive full screen mode according to Using Immersive Full-Screen Mode

But first of all it perfect fine when I select Make Immersive button, app is entering immersion fullscreen mode. Perfect for First Time

My problem is after selecting the Cancel Immersive button, and select Make Immsersive again. Although app is immersive mode, in the place of status bar is being white

Status bar place is being white

Here is my hide and show functions

private void hideSystemUI() {
        // Set the IMMERSIVE flag.
        // Set the content to appear under the system bars so that the content
        // doesn't resize when the system bars hide and show.
        View mDecorView = getWindow().getDecorView();
        mDecorView.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);
    }

    private void showSystemUI() {
        View mDecorView = getWindow().getDecorView();
        mDecorView.setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                         |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }

and my activity_main.xml is

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context="com.example.aungmyolwin.immsersivedelete.MainActivity">

        <Button
            android:id="@+id/btn_immersive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="make immersive" />

        <Button
            android:id="@+id/btn_cancel_immersive"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="cancle immersive" />

        <Button
            android:id="@+id/btn_show_dialog"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="show dialog" />

    </LinearLayout>
</FrameLayout>

Upvotes: 2

Views: 2721

Answers (2)

amlwin
amlwin

Reputation: 4329

I solved this for temporary. Doing requestLayout after making fullscreen mode

Here is my codes

    getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
    getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);

findViewById(android.R.id.content).requestLayout();
View mDecorView = getWindow().getDecorView();

                mDecorView.setSystemUiVisibility(
                        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);

Upvotes: 3

Arya
Arya

Reputation: 1747

make transparent the status bar in your theme

<item name="android:statusBarColor">@android:color/transparent</item>
<item name="android:windowNoTitle">true</item>
<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

onCreate

Window window = getWindow();
WindowManager.LayoutParams winParams = window.getAttributes();
winParams.flags &= ~WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS;
window.setAttributes(winParams);

window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                     |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

Upvotes: 2

Related Questions