android 全屏切换

    private void fullscreen(boolean enable) {

        View decorView = getWindow().getDecorView();
        if (enable) { //隐藏状态栏
//            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
//            getWindow().setAttributes(lp);
//            getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

            if (Build.VERSION.SDK_INT < 19) {
                decorView.setSystemUiVisibility(View.VISIBLE);
            } else {
                int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
                decorView.setSystemUiVisibility(uiOptions);
            }
        } else { //显示状态栏
//            WindowManager.LayoutParams lp = getWindow().getAttributes();
//            lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
//            getWindow().setAttributes(lp);
//            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);

            if (Build.VERSION.SDK_INT < 19) {
                decorView.setSystemUiVisibility(View.GONE);
            } else {
                int uiOptions = View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY ;
                decorView.setSystemUiVisibility(uiOptions);
            }
        }
    }

 

你可能感兴趣的:(android 全屏切换)