Solution of Android dialog Removing Virtual Keys
- 2021-09-20 21:39:05
- OfStack
Some models of Android have no physical keys, only virtual keys. The full-screen method of Activity is as follows:
1. In
setContentView(R.layout.activity_main); Add before
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
2. When the user draws the virtual key, the automatic re-hiding method is as follows:
getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
@Override
public void onSystemUiVisibilityChange(int visibility) {
int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
// The layout is below the status bar
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
// Full screen
View.SYSTEM_UI_FLAG_FULLSCREEN |
// Hide the navigation bar
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 hiding method
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 |
// The layout is below the status bar
View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
// Full screen
View.SYSTEM_UI_FLAG_FULLSCREEN |
// Hide the navigation bar
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);
}
}); To be in mDialog.show(); Before.