【问题标题】:How to completely exit from Immersive full screen mode?如何完全退出沉浸式全屏模式?
【发布时间】:2014-03-07 04:21:58
【问题描述】:

我想实现一个按钮来启用/禁用沉浸式全屏模式。我正在使用这些方法,但 showSystemUI 只能快速显示并再次隐藏...

如何完全退出沉浸式模式?

我的方法:

// This snippet hides the system bars.
    @SuppressLint("NewApi")
    private void hideSystemUI() {
        try{
            // 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.
            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 // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE);
        }catch(Exception e){
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    // This snippet shows the system bars. It does this by removing all the flags
    // except for the ones that make the content appear under the system bars.
    @SuppressLint("NewApi")
    private void showSystemUI() {
        try{
            mDecorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }catch(Exception e){
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

            mDecorView.setVisibility(View.GONE);
            mDecorView.setVisibility(View.VISIBLE);
            WindowManager.LayoutParams attrs = getWindow().getAttributes();
            attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
            getWindow().setAttributes(attrs);
            mDecorView.setPadding(0, getStatusBarHeight(), 0, 0);
        }
    }

如何让内容再次出现在系统栏下方?

【问题讨论】:

  • 你在哪里调用这些方法?
  • 在 ToggleButton 的 onClick 方法中。如果 FullScreenButton isChecked,则调用 hideSystemUi。如果未选中 FullScreenButton,则调用 showSystemUI。 (请记住,这仅在单击全屏按钮时调用。
  • :) 分享完整代码,以便我测试它
  • 代码只有这两个Button调用了这个方法。如果在全屏模式下单击,则会进入沉浸式全屏,调用方法 hideSystemUI。但是如果你点击返回全屏,方法 showSystemUI 会被调用,但应用程序不会返回非全屏模式...

标签: android fullscreen android-4.4-kitkat android-fullscreen


【解决方案1】:

使用 View.SYSTEM_UI_FLAG_VISIBLE 调用 setSystemUiVisibility() 会清除所有标志:

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

【讨论】:

    【解决方案2】:

    对我有用的是:

    View decorView = activity.getWindow().getDecorView();
    decorView.setSystemUiVisibility(0);
    

    我可能错了,但似乎用0 调用setSystemUiVisibility 会清除以前应用的标志。

    【讨论】:

    猜你喜欢
    • 2016-08-25
    • 2014-03-06
    • 2013-12-23
    • 1970-01-01
    • 2016-10-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-10
    相关资源
    最近更新 更多