activity realizes immersive effect in full screen and the method of touching alone will not pop up virtual keys

  • 2021-09-24 23:32:15
  • OfStack

Method 1:

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


mLCDChangeLayout.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION|
 View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY);

mLCDChangeLayout can be any one control in the layout of activity. The first flags mainly realizes the function of hiding NavigationBar, while the last flags will not pop up NavigationBar when touching, but will only pop up when pulling down the status bar and other system gestures.

Mode 2:

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


@Override
 public void onWindowFocusChanged(boolean hasFocus) {
  super.onWindowFocusChanged(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;
  decorView.setSystemUiVisibility(flags);
  decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
   @Override
   public void onSystemUiVisibilityChange(int visibility) {
    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
     decorView.setSystemUiVisibility(flags);
    }
   }
  });
 }

Then call the method of hideNavigationBar in the onWindowFocusChanged method, which is similar to Mode 1.


Related articles: