SoFunction
Updated on 2025-04-10

The method of realizing immersive effect in full screen, and not popping up virtual keys when touched alone

Method 1:

Set the activity's theme property to hide the title bar and status bar, and then call the method in the onWindowFocusChanged method

(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

mLCDChangeLayout can be any control in the activity layout. The previous flags mainly implement the function of hiding the NavigationBar, and the latter flags will not pop up the NavigationBar when touched, and will pop up only when some system gestures such as the pull-down status bar.

Method 2:

The activity attribute does not need to be set, and the following method is added directly to the activity:

@Override
 public void onWindowFocusChanged(boolean hasFocus) {
  (hasFocus);
  if( hasFocus ) {
   hideNavigationBar();
  }
 }
 private void hideNavigationBar() {
  // TODO Auto-generated method stub
  final View decorView = getWindow().getDecorView();
  final int flags = View.SYSTEM_UI_FLAG_LAYOUT_STABLE
    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
    | View.SYSTEM_UI_FLAG_FULLSCREEN
    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
  (flags);
  (new () {
   @Override
   public void onSystemUiVisibilityChange(int visibility) {
    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
     (flags);
    }
   }
  });
 }

Then call the hideNavigationBar method in the onWindowFocusChanged method, the principle is similar to the method.

The above method of the activity full screen achieves immersive effect, and the virtual buttons will not pop up when touched alone is all the content I share with you. I hope you can give you a reference and I hope you can support me more.