1. Window方式
if (mIsFullScreen){//設置爲非全屏
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.flags &= (~WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().setAttributes(lp);
getWindow().clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}else{//設置爲全屏
WindowManager.LayoutParams lp = getWindow().getAttributes();
lp.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
getWindow().setAttributes(lp);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
2. View方式
if (mIsFullScreen){//設置爲非全屏
getWindow().getDecorView().
setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
}else{//設置爲全屏
getWindow().getDecorView().
setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN);
}