美文网首页Android之界面Android进阶
Android隐藏状态栏、导航栏

Android隐藏状态栏、导航栏

作者: 灰灰手记 | 来源:发表于2017-08-23 09:34 被阅读3343次

    Android隐藏状态栏、导航栏

    private void hideStatusNavigationBar(){  
        if(Build.VERSION.SDK_INT<16){  
            this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,  
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);  
        }else{  
            int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN  
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION  
                    | View.SYSTEM_UI_FLAG_FULLSCREEN //hide statusBar  
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION; //hide navigationBar  
            getWindow().getDecorView().setSystemUiVisibility(uiFlags);  
        }  
    }
    

    Android 动态隐藏显示导航栏,状态栏

    一、导航栏:
    private void hideNavigationBar() {  
        View decorView = getWindow().getDecorView();  
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION  
                | View.SYSTEM_UI_FLAG_FULLSCREEN;  
        decorView.setSystemUiVisibility(uiOptions);  
    }  
      
    private void showNavigationBar() {  
        View decorView = getWindow().getDecorView();  
        int uiOptions = View.SYSTEM_UI_FLAG_VISIBLE;  
        decorView.setSystemUiVisibility(uiOptions);  
    }
    

    相关:

    Attr Des
    SYSTEM_UI_FLAG_VISIBLE 显示状态栏和导航栏
    SYSTEM_UI_FLAG_LOW_PROFILE 此模式下,状态栏的图标可能是暗的
    SYSTEM_UI_FLAG_HIDE_NAVIGATION 隐藏导航栏
    SYSTEM_UI_FLAG_FULLSCREEN 全屏,隐藏状态栏和导航栏
    SYSTEM_UI_FLAG_LAYOUT_STABLE
    SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN 全屏,隐藏导航栏,状态栏浮在布局上
    SYSTEM_UI_FLAG_IMMERSIVE 沉浸式:半透明的状态栏和导航栏
    SYSTEM_UI_FLAG_IMMERSIVE_STICKY 粘性沉浸式
    二、状态栏:
    private void setStatusBarVisible(boolean show) {  
        if (show) {  
            int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;  
            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);  
        }  
    }
    
    三、导航栏和状态栏
    private void setSystemUIVisible(boolean show) {  
        if (show) {  
            int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE;  
            uiFlags |= 0x00001000;  
            getWindow().getDecorView().setSystemUiVisibility(uiFlags);  
        } else {  
            int uiFlags = 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;  
            uiFlags |= 0x00001000;  
            getWindow().getDecorView().setSystemUiVisibility(uiFlags);  
        }  
    }
    

    相关文章

      网友评论

        本文标题:Android隐藏状态栏、导航栏

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