如何隐藏/显示状态栏

时间:2017-01-15 11:00:23

标签: android android-notification-bar

我想在活动外显示/隐藏状态栏。

我的代码如下:

activity.getWindow().getDecorView()
    .setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);

它对我不起作用。 activity.getWindow()返回null。

2 个答案:

答案 0 :(得分:1)

  

使用沉浸式全屏模式

隐藏/显示 - 在您的活动中

// Hide status bar
getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

// Show status bar
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

更多Post

答案 1 :(得分:0)

View decorView = getWindow().getDecorView();
decorView.setOnSystemUiVisibilityChangeListener
        (new View.OnSystemUiVisibilityChangeListener() {
    @Override
    public void onSystemUiVisibilityChange(int visibility) {
        // Note that system bars will only be "visible" if none of the
        // LOW_PROFILE, HIDE_NAVIGATION, or FULLSCREEN flags are set.
        if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
            // TODO: The system bars are visible. Make any desired
            // adjustments to your UI, such as showing the action bar or
            // other navigational controls.
        } else {
            // TODO: The system bars are NOT visible. Make any desired
            // adjustments to your UI, such as hiding the action bar or
            // other navigational controls.
        }
    }
});

有关详细信息,请参阅此链接。

https://developer.android.com/training/system-ui/visibility.html