美文网首页
沉浸式页面状态栏隐藏和显示控制

沉浸式页面状态栏隐藏和显示控制

作者: hahauha | 来源:发表于2019-12-25 20:05 被阅读0次

    activity 中设置

        @Override
        public void onWindowFocusChanged(boolean hasFocus) {
            super.onWindowFocusChanged(hasFocus);
            if (hasFocus) {
    //            int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
                int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
                uiFlags |= 0x00001000;
                getWindow().getDecorView().setSystemUiVisibility(uiFlags);
            } else {
                int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_FULLSCREEN;
                uiFlags |= 0x00001000;
                getWindow().getDecorView().setSystemUiVisibility(uiFlags);
            }
        }
    
    

    dialog中设置

        @Override
        public void onWindowFocusChanged(boolean hasFocus) {
    
            if (hasFocus){
                int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                        | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_FULLSCREEN;
                uiFlags |= 0x00001000;
                getWindow().getDecorView().setSystemUiVisibility(uiFlags);
            }
    

    必须同时设置才生效

    相关文章

      网友评论

          本文标题:沉浸式页面状态栏隐藏和显示控制

          本文链接:https://www.haomeiwen.com/subject/oagbictx.html