Android 中隐藏虚拟按键的方法实例代码

下面通过一段代码给大家讲解android 隐藏虚拟按键的方法,废话不多说了,大家多多看看代码和注释吧,具体代码如下所示:

 /**
   * 隐藏虚拟按键,并且全屏
   */
  protected void hideBottomUIMenu() {
    //隐藏虚拟按键,并且全屏
    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);
    }
  }
//隐藏虚拟按键,并且全屏
    getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
        | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
    getWindow().getDecorView().setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
      @Override
      public void onSystemUiVisibilityChange(int visibility) {
        getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN);
      }
    });

例子

import android.app.Activity; 
import android.os.Bundle; 
import android.view.View; 
import android.view.View.OnClickListener; 
public class HideTestActivity extends Activity implements OnClickListener{ 
  View main ; 
  /** Called when the activity is first created. */ 
  @Override 
  public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    main = getLayoutInflater().from(this).inflate(R.layout.main, null); 
    main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); 
    main.setOnClickListener(this); 
    setContentView(main); 
  } 
  @Override 
  public void onClick(View v) { 
    int i = main.getSystemUiVisibility(); 
    if (i == View.SYSTEM_UI_FLAG_HIDE_NAVIGATION) { 
      main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE); 
    } else if (i == View.SYSTEM_UI_FLAG_VISIBLE){ 
      main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_LOW_PROFILE); 
    } else if (i == View.SYSTEM_UI_FLAG_LOW_PROFILE) { 
      main.setSystemUiVisibility(View.SYSTEM_UI_FLAG_HIDE_NAVIGATION); 
    } 
  } 
} 

以上所述是小编给大家介绍的Android 中隐藏虚拟按键的方法实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对呐喊教程网站的支持!

声明:本文内容来源于网络,版权归原作者所有,内容由互联网用户自发贡献自行上传,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任。如果您发现有涉嫌版权的内容,欢迎发送邮件至:notice#nhooo.com(发邮件时,请将#更换为@)进行举报,并提供相关证据,一经查实,本站将立刻删除涉嫌侵权内容。