Solve the problem that Android virtual keys obscure the page content

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

When launching the page, Huawei's mobile phone virtual buttons blocked the words below the launching page and found a solution, specially recording 1

Method 1: Extend virtual keys


// Status bar  @  Top getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);//A
// Navigation bar  @  Bottom getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);//B
// Which layout this is added to, the layout will go up accordingly (configuration A ) or down (configure B ) or up and down (configure both AB ) 
 Expand android:fitsSystemWindows="true"

Method 2: Hide the keys


 /**
  *  Hide virtual keys and full screen 
  */
 protected void hideBottomUIMenu() {
  // Hide virtual keys and full screen 
  if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api
   View v = this.getWindow().getDecorView();
   v.setSystemUiVisibility(View.GONE);
  } else if (Build.VERSION.SDK_INT >= 19) {
   //for new api versions.
   View decorView = getWindow().getDecorView();
   int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
       | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN;
   decorView.setSystemUiVisibility(uiOptions);
  }
 }

Related articles: