简体   繁体   English

如何在Oreo中禁用状态栏?

[英]How to disable status bar in Oreo?

There are many question related to disable status bar. 与禁用状态栏有关的问题很多。

I tried that way. 我尝试过这种方式。 But did not work in Android 8.0. 但是在Android 8.0中不起作用。

because according to Google Document 因为根据Google Document

Alert windows If an app uses the SYSTEM_ALERT_WINDOW permission and uses one of the following window types to attempt to display alert windows above other apps and system windows: 警报窗口如果某个应用程序使用SYSTEM_ALERT_WINDOW权限并使用以下窗口类型之一尝试在其他应用程序和系统窗口上方显示警报窗口:

TYPE_PHONE
TYPE_PRIORITY_PHONE
TYPE_SYSTEM_ALERT
TYPE_SYSTEM_OVERLAY
TYPE_SYSTEM_ERROR

...then these windows always appear beneath the windows that use the TYPE_APPLICATION_OVERLAY window type. ...然后,这些窗口将始终出现在使用TYPE_APPLICATION_OVERLAY窗口类型的窗口下方。 If an app targets Android 8.0 (API level 26), the app uses the TYPE_APPLICATION_OVERLAY window type to display alert windows. 如果某个应用程序针对Android 8.0(API级别26),则该应用程序将使用TYPE_APPLICATION_OVERLAY窗口类型来显示警报窗口。

I already tried How to disable status bar click and pull down in Android? 我已经尝试过如何在Android中禁用状态栏的单击和下拉? but this works only below Android 8.0. 但这仅在Android 8.0以下有效。

How to disable status bar in Android 8.0? 如何在Android 8.0中禁用状态栏?

Have you tried something with the flag SYSTEM_UI_FLAG_FULLSCREEN ? 您是否尝试过使用SYSTEM_UI_FLAG_FULLSCREEN标志?

Since I'm not sure exactly what your looking for I'll try to give a generic answer that you can tweak to your use case. 由于我不确定您到底在寻找什么,因此我将尝试给出一个通用的答案,您可以对该用例进行调整。 I hope it helps someone. 希望对您有所帮助。

Play around with the different flags in here and see what all you need. 在这里玩各种标志,看看您需要什么。 By the sounds of it you probably just need the last flag -- unless you wish to hide the navigation as well -- then you'll probably want the last two flags set. 听起来,您可能只需要最后一个标志-除非您也希望隐藏导航-然后您可能需要设置最后两个标志。

private void hideSystemUI() {
    // Enables regular immersive mode.
    // For "lean back" mode, remove SYSTEM_UI_FLAG_IMMERSIVE.
    // Or for "sticky immersive," replace it with SYSTEM_UI_FLAG_IMMERSIVE_STICKY
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE
            // Set the content to appear under the system bars so that the
            // content doesn't resize when the system bars hide and show.
            | View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN
    );
}

Then take and implement this new method by overriding the onWindowFocusChanged( ... ) method like so. 然后像这样通过重写onWindowFocusChanged( ... )方法来采用并实现此新方法。

@Override
public void onWindowFocusChanged(boolean hasFocus) {
    super.onWindowFocusChanged(hasFocus);

    if (hasFocus) {
        hideSystemUI();
    }
}

Maybe you'll even want to experiment with adding in some logic to what flags are used under which circumstances or states of the application. 也许您甚至想尝试在应用程序的哪种情况或状态下使用一些标志添加一些逻辑。

Another great resource as always is Google's docs. 与往常一样,另一个很棒的资源是Google的文档。 There is good info on controlling the system UI visibility here . 有对控制系统的用户界面的可视性良好的信息在这里

See the answer here. 在这里查看答案。 We can't block status bar in Oreo. 我们无法在Oreo中阻止状态栏。 Only can close using a service. 只有使用服务才能关闭。

https://stackoverflow.com/a/56292743/3405508 https://stackoverflow.com/a/56292743/3405508

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM