Status Bar is white when entering immersive full screen mode

泪湿孤枕 提交于 2019-12-13 03:45:37

问题


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.

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

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>

回答1:


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



回答2:


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


来源:https://stackoverflow.com/questions/48660224/status-bar-is-white-when-entering-immersive-full-screen-mode

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!