如何完全从沉浸式全屏模式退出? [英] How to completely exit from Immersive full screen mode?

查看:1136
本文介绍了如何完全从沉浸式全屏模式退出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I would like to implement a button to enable/disable the immersive full screen mode. I'm using those methods but the showSystemUI only shows quickly and hide again...

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

How to completely exit from immersive mode?

我的方法:

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

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

How to make the content appear under the system bars again?

推荐答案

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

Calling setSystemUiVisibility() with View.SYSTEM_UI_FLAG_VISIBLE clears all flags:

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

这篇关于如何完全从沉浸式全屏模式退出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆