0

我有一个带有 2 个工具栏的活动,一个在顶部,一个在底部。我使用反转模式,现在效果很好,它允许用户向下拖动状态栏......

问题是,状态栏被拉下来之后就再也隐藏不起来了……

我在这里找到了一些解决方案,但我无法让它工作。状态栏要么显示在我的视图上,要么如果我打开溢出菜单就会混乱,或者它不会再次隐藏......

这是我目前使用的:

@Override
protected void onResume()
{
    super.onResume();
    enableFullScreenMode();
}

private void enableFullScreenMode()
{
    if (Build.VERSION.SDK_INT < 16)
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
    else
        getWindow().getDecorView().setSystemUiVisibility(
                View.SYSTEM_UI_FLAG_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
//                            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        );
}

我想要的是

  • 始终全屏,直到用户向下拖动状态栏
  • 例如 3 秒后状态栏应该再次隐藏,如果它没有打开
  • 关闭状态栏后应该再次隐藏
  • 在工具栏中打开我的溢出菜单时,状态栏不应该出现
4

3 回答 3

2

The answer is, Sticker immersive mode.

As the doc says:

"The bars automatically disappear after a few seconds of no interaction or as soon as the user touches or gestures anywhere outside the system bars."

private void hideSystemUI() {
    View decorView = getWindow().getDecorView();
    decorView.setSystemUiVisibility(
            View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY
                    | 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);
}
于 2019-07-04T11:13:52.817 回答
1

//1.把这个放在点击之后。

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

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

//2.Remove "android:fitsSystemWindows="true"" 从你布局的任何地方。

//3.像这样在onResumes中添加hideSystemUI()(用于自动重新隐藏状态和底部导航)。

@Override
public void onResume() {
    super.onResume();
    hideSystemUI();
}
于 2019-03-06T10:29:11.350 回答
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.
        }
    }
});
于 2015-10-21T12:50:26.927 回答