Android 部分机型没有物理按键,只有虚拟按键,Activity全屏方法如下:
在
1
setContentView(R.layout.activity_main);
之前添加
1
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
当用户划出虚拟按键后,自动再隐藏方法如下:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
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); } });
dialog 隐藏方法
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
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();之前。
dialog 隐藏方法,放在自定义dialog中即可
1 2 3 4
@Override public void onStart() { super.onStart(); Window window = this.getWindow();
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
//如果是在activity中则用这段代码 //Window window = getDialog().getWindow(); window.setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); // 用在activity中,去标题 //window.requestWindowFeature(Window.FEATURE_NO_TITLE); int uiOptions =View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_LAYOUT_STABLE |View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |View.SYSTEM_UI_FLAG_IMMERSIVE |View.SYSTEM_UI_FLAG_FULLSCREEN window.getDecorView().setSystemUiVisibility(uiOptions); } |