美文网首页
状态栏控制显示隐藏

状态栏控制显示隐藏

作者: eoeoops | 来源:发表于2018-06-26 10:53 被阅读7次
        protected void setTranslucentStatuBar(){
            if (Build.VERSION.SDK_INT >= 21) {
                decorView = getWindow().getDecorView();
                int option = View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                        | View.SYSTEM_UI_FLAG_LAYOUT_STABLE;
                decorView.setSystemUiVisibility(option);
                getWindow().setStatusBarColor(Color.TRANSPARENT);
    
                statusbarHeight = getStatusBarHeight();
            }
        }
    
        protected void toggleStatusBar(){
            if (Build.VERSION.SDK_INT >= 21) {
                if (decorView.getSystemUiVisibility() != (View.SYSTEM_UI_FLAG_FULLSCREEN)) {
                    decorView.setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
                } else {
                    setTranslucentStatuBar();
                }
            }
        }
    
        protected int getStatusBarHeight() {
            int result = 0;
            int resourceId = this.getResources().getIdentifier("status_bar_height", "dimen", "android");
            if (resourceId > 0) {
                result = getResources().getDimensionPixelSize(resourceId);
            }
            return result;
        }
    

    相关文章

      网友评论

          本文标题:状态栏控制显示隐藏

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