也没什么特别的,主要是可能在高版本上出现页面跳动或闪烁,直接上代码,
private void setSystemUIVisible(boolean visible){
Window window = mWindow;
if(window == null){
return;
}
WindowManager.LayoutParams attr = window.getAttributes();
if(visible){
attr.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;
window.setAttributes(attr);
}else{
attr.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;
window.setAttributes(attr);
window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
}
//或者使用下面
// if(visible){
// window.clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// window.addFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
// }else{
// window.clearFlags(WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN);
// window.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
// }
}
解决闪烁问题,可以在在Activity oncreat里添加代码:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.P) {
WindowManager.LayoutParams lp = getWindow().getAttributes();
if(lp != null){
lp.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES;
getWindow().setAttributes(lp);
}
}