最近有个平板项目,需要将状态栏和导航条进行隐藏,找了好一会的资料
代码
public static void hideStatusNavigationBar(Activity activity) {
if(Build.VERSION.SDK_INT<16){
activity.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
WindowManager.LayoutParams.FLAG_FULLSCREEN);
}else{
int uiFlags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
| View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
| View.SYSTEM_UI_FLAG_FULLSCREEN
| View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY; //hide navigationBar
activity.getWindow().getDecorView().setSystemUiVisibility(uiFlags);
}
}
在OnCreate中编写下面代码:
this.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
ScreenUtil.hideStatusNavigationBar(this);
}
});
ScreenUtil.hideStatusNavigationBar(this);
评论区