SoFunction
Updated on 2025-04-05

Android dialog solution to remove virtual keys

Some Android models do not have physical buttons, only virtual buttons, and the full screen method of Activity is as follows:

1. In

setContentView(.activity_main);Added before
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);

2. When the user marks out the virtual button, the automatic hidden 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 located below the status bar        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
        //full screen        View.SYSTEM_UI_FLAG_FULLSCREEN |
        //Hide navigation bar        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    if (.SDK_INT >= 19) {
      uiOptions |= 0x00001000;
    } else {
      uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
    }
    getWindow().getDecorView().setSystemUiVisibility(uiOptions);
  }
});

3. Dialog hidden method

().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION);
().getDecorView().setOnSystemUiVisibilityChangeListener(new OnSystemUiVisibilityChangeListener() {
  @Override
  public void onSystemUiVisibilityChange(int visibility) {
    int uiOptions = View.SYSTEM_UI_FLAG_LAYOUT_STABLE |
        //The layout is located below the status bar        View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION |
        //full screen        View.SYSTEM_UI_FLAG_FULLSCREEN |
        //Hide navigation bar        View.SYSTEM_UI_FLAG_HIDE_NAVIGATION |
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
    if (.SDK_INT >= 19) {
      uiOptions |= 0x00001000;
    } else {
      uiOptions |= View.SYSTEM_UI_FLAG_LOW_PROFILE;
    }
    ().getDecorView().setSystemUiVisibility(uiOptions);
  }
});To be();Before。

The above solution to removing virtual buttons in Android dialog is all the content I share with you. I hope you can give you a reference and I hope you can support me more.