首页 > 系统 > Android > 正文

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

2019-12-12 04:14:31
字体:
来源:转载
供稿:网友

下面通过一段代码给大家讲解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 中隐藏虚拟按键的方法实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对武林网网站的支持!

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表