状态栏控制显示隐藏

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

你可能感兴趣的:(状态栏控制显示隐藏)