Android 弹出Dialog时隐藏状态栏和底部导航栏的方法
程序员文章站
2022-11-23 08:07:03
上代码
dialog.getwindow().getdecorview().setsystemuivisibility(view.system_ui_...
上代码
dialog.getwindow().getdecorview().setsystemuivisibility(view.system_ui_flag_hide_navigation); dialog.getwindow().getdecorview().setonsystemuivisibilitychangelistener(new view.onsystemuivisibilitychangelistener() { @override public void onsystemuivisibilitychange(int visibility) { int uioptions = view.system_ui_flag_layout_stable | //布局位于状态栏下方 view.system_ui_flag_layout_hide_navigation | //全屏 view.system_ui_flag_fullscreen | //隐藏导航栏 view.system_ui_flag_hide_navigation | view.system_ui_flag_layout_fullscreen; uioptions |= 0x00001000; dialog.getwindow().getdecorview().setsystemuivisibility(uioptions); } });
ps:下面看下android dialog弹出时不显示导航栏(沉浸式)
我们的app是全屏沉浸式的,发现activity在设置了全屏后,弹出dialog底部会跳出导航栏虚拟键。具体原因是因为dialog的window抢走了焦点,window 中的 decorview 状态改变导致了退出。
解决方法,在dialog中:
private void fullscreenimmersive(view view) { if (build.version.sdk_int >= build.version_codes.kitkat) { int uioptions = view.system_ui_flag_layout_stable | view.system_ui_flag_layout_hide_navigation | view.system_ui_flag_hide_navigation | view.system_ui_flag_immersive_sticky | view.system_ui_flag_layout_fullscreen | view.system_ui_flag_fullscreen; view.setsystemuivisibility(uioptions); } } @override public void show() { this.getwindow().setflags(windowmanager.layoutparams.flag_not_focusable, windowmanager.layoutparams.flag_not_focusable); super.show(); fullscreenimmersive(getwindow().getdecorview()); this.getwindow().clearflags(windowmanager.layoutparams.flag_not_focusable); }
总结
以上所述是小编给大家介绍的android 弹出dialog时隐藏状态栏和底部导航栏的方法,希望对大家有所帮助
上一篇: 生活体会