Android dialog 去除虚拟按键的解决方法
Android 部分机型没有物理按键,只有虚拟按键,Activity全屏方法如下:
1、在
setContentView(R.layout.activity_main);之前添加
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
2、当用户划出虚拟按键后,自动再隐藏方法如下:
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new 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; if (Build.VERSION.SDK_INT >= 19) { uiOptions |= 0x00001000; } else { uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE; } getWindow().getDecorView().setSystemUiVisibility(uiOptions); } });
3、dialog 隐藏方法
mDialog.getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); mDialog.getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new 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; if (Build.VERSION.SDK_INT >= 19) { uiOptions |= 0x00001000; } else { uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE; } mDialog.getWindow().getDecorView().setSystemUiVisibility(uiOptions); } });要在mDialog.show();之前。
以上这篇Android dialog 去除虚拟按键的解决方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持我们。
赞 (0)