@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);
}
}
原文链接:https://www.cnblogs.com/94cool/p/17293465.html
本站文章如无特殊说明,均为本站原创,如若转载,请注明出处:Android 11全屏显示 - Python技术站