【Android】隐藏底部虚拟按键,亲测可用
16lz
2021-01-23
Google的官方文档是:
https://developer.android.com/training/system-ui/navigation.html#behind
示例代码
View decorView = getWindow().getDecorView();// Hide both the navigation bar and the status bar.// SYSTEM_UI_FLAG_FULLSCREEN is only available on Android 4.1 and higher, but as// a general rule, you should design your app to hide the status bar whenever you// hide the navigation bar.int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_FULLSCREEN;decorView.setSystemUiVisibility(uiOptions);
原文
但是,有个问题。
这样的确能隐藏底部虚拟导航栏,但是一旦你点击屏幕,导航栏会出现(持续1秒左右),并且消费掉你的点击事件。如果你要点击一个按钮(导航栏隐藏状态下),你需要连续点两次。因为1秒钟之后,导航栏又消失了,点击屏幕事件会被再次拦截消费。
最终的解决方案
测试机型:华为 TIT-TL00
/** * 隐藏虚拟按键,并且全屏 */ protected void hideBottomUIMenu() { //隐藏虚拟按键,并且全屏 if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api View v = this.getWindow().getDecorView(); v.setSystemUiVisibility(View.GONE); } else if (Build.VERSION.SDK_INT >= 19) { //for new api versions. View decorView = getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions); } }
希望对你有用~
更多相关文章
- android camera根据屏幕图像大小设置显示
- android获取设备屏幕分辨率的方法
- android 笔记:判断手机是否显示虚拟按键
- Android 下保持屏幕常亮的实现方法
- Android屏幕录制
- 捕获Android文本输入框的软键盘完成(Done)按键消息
- Android保持屏幕常亮的方法
- ListView的长按键事件的处理
- android 唤醒和解锁屏幕