进入沉浸式全屏模式时,状态栏为白色

时间:2018-02-07 09:31:15

标签: android android-theme android-fullscreen

我根据Using Immersive Full-Screen Mode

制作了一个关于沉浸式全屏模式的简单项目

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

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

Status bar place is being white

这是我的隐藏和显示功能

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>

2 个答案:

答案 0 :(得分:0)

使主题中的状态栏变为透明

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

答案 1 :(得分:0)

我暂时解决了这个问题。完成全屏模式后执行 Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 11, in <module> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' Error in sys.excepthook: Traceback (most recent call last): File "/usr/lib/python3/dist-packages/apport_python_hook.py", line 63, in apport_excepthook from apport.fileutils import likely_packaged, get_recent_crashes File "/usr/lib/python3/dist-packages/apport/__init__.py", line 5, in <module> from apport.report import Report File "/usr/lib/python3/dist-packages/apport/report.py", line 30, in <module> import apport.fileutils File "/usr/lib/python3/dist-packages/apport/fileutils.py", line 23, in <module> from apport.packaging_impl import impl as packaging File "/usr/lib/python3/dist-packages/apport/packaging_impl.py", line 23, in <module> import apt File "/usr/lib/python3/dist-packages/apt/__init__.py", line 23, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg' Original exception was: Traceback (most recent call last): File "/usr/bin/add-apt-repository", line 11, in <module> from softwareproperties.SoftwareProperties import SoftwareProperties, shortcut_handler File "/usr/lib/python3/dist-packages/softwareproperties/SoftwareProperties.py", line 27, in <module> import apt_pkg ModuleNotFoundError: No module named 'apt_pkg'

这是我的代码

requestLayout