【问题标题】:Status Bar is white when entering immersive full screen mode进入沉浸式全屏模式时状态栏为白色
【发布时间】:2018-07-17 12:45:50
【问题描述】:

我根据Using Immersive Full-Screen Mode做了一个关于沉浸式全屏模式的简单项目

但首先,当我选择Make Immersive 按钮时,应用程序正在进入沉浸式全屏模式。

我的问题是在选择Cancel Immersive 按钮后,再次选择Make Immsersive。虽然app是沉浸模式,但是状态栏的地方是白色的

这是我的隐藏和显示功能

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

我的activity_main.xml

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

【问题讨论】:

    标签: android android-theme android-fullscreen


    【解决方案1】:

    使主题中的状态栏透明

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

    我暂时解决了这个问题。做全屏模式后做requestLayout

    这是我的代码

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

    【讨论】:

      猜你喜欢
      • 2016-08-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-07
      • 2015-07-04
      • 2014-03-06
      • 1970-01-01
      • 2013-12-23
      相关资源
      最近更新 更多