【问题标题】:How to hide status bar on Android Q? [duplicate]如何在 Android Q 上隐藏状态栏? [复制]
【发布时间】:2019-08-12 11:25:19
【问题描述】:

我无法在 Android Q 上隐藏状态栏。当我在拆分视图中隐藏它时,它变成白色,而不是黑色。但是,如果我不在拆分视图中,一切都很好。 我是怎么做的:

public void hideSystemUI() {
    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);
}

这只是一个错误还是我应该使用其他方式?我尝试了官方文档中的方法,但效果很差,而且栏还是白色的。

注意:问题是它是白色的,而不是它没有隐藏并且仅在分屏模式下。全屏不是一个选项,我需要动态隐藏它。它仅适用于 Q!它不是重复的。请仔细阅读。

【问题讨论】:

    标签: android android-statusbar


    【解决方案1】:

    @Abhinav 的回答是正确的,但是如果你想使用官方文档,你应该使用setSystemUiVisibility()。像这样:

    View decorView = getWindow().getDecorView();
    // Hide the status bar.
    int uiOptions = View.SYSTEM_UI_FLAG_FULLSCREEN;
    decorView.setSystemUiVisibility(uiOptions);
    // Remember that you should never show the action bar if the
    // status bar is hidden, so hide that too if necessary.
    ActionBar actionBar = getActionBar();
    actionBar.hide();
    

    另外,在 styles.xml 文件中设置主题,而不是在清单中。像这样:

    <item name="android:windowFullscreen">true</item>
    

    将此添加到您的样式中。

    欲了解更多信息,请查看:https://developer.android.com/training/system-ui/status

    如果您仍然支持 API 16 及更低版本,请使用 @Abhinav 的代码。它检查这两种情况。如果没有,请使用此处列出的那个。

    如果你想隐藏你的工具栏试试这个代码:

    <style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
        <!-- Customize your theme here. -->
        <item name="colorPrimary">@color/colorPrimary</item>
        <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
        <item name="colorAccent">@color/colorAccent</item>
        <item name="android:windowFullscreen">true</item>
    </style>
    

    将其粘贴到您的 styles.xml 文件中。或者,如果您想要 DarkLight 替换为 Dark 并删除 NoActionBar

    【讨论】:

    • 那行不通。正如我所提到的,我尝试了官方文档中的方式。 Q 上的条仍然是白色的。问题是它是白色的,而不是因为我不知道要隐藏。
    • 白色是什么意思?好像它是隐藏的但白色的?
    • 试试我的编辑,可能对你有帮助
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-22
    • 1970-01-01
    • 2017-01-08
    • 2012-02-28
    • 2017-10-08
    • 1970-01-01
    • 2013-11-20
    相关资源
    最近更新 更多