@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//去掉标题栏
this.requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(ActivityLoginBinding.inflate(getLayoutInflater()).getRoot());
//设置全屏
WindowInsetsController controller = getWindow().getInsetsController();
controller.hide(WindowInsets.Type.systemBars());
int behavior3 = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
controller.setSystemBarsBehavior(behavior3);
}
如果有编辑还是显示导航栏的解决方案(重写onWindowFocusChanged):
/**
* 全屏显示
*
* @param hasFocus
*/
@Override
public void onWindowFocusChanged(boolean hasFocus) {
super.onWindowFocusChanged(hasFocus);
if (hasFocus) {
WindowInsetsController controller = getWindow().getInsetsController();
// 隐藏状态栏 导航栏 同时隐藏状态栏和导航栏
controller.hide(WindowInsets.Type.systemBars());
// 向后模式
int behavior1 = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_TOUCH;
// 沉浸模式
int behavior2 = WindowInsetsController.BEHAVIOR_SHOW_BARS_BY_SWIPE;
// 粘性沉浸模式
int behavior3 = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE;
controller.setSystemBarsBehavior(behavior3);
}
}
内容来源于网络如有侵权请私信删除
文章来源: 博客园
- 还没有人评论,欢迎说说您的想法!