欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

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

程序员文章站 2024-02-23 15:39:34
下面通过一段代码给大家讲解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 中隐藏虚拟按键的方法实例代码,希望对大家有所帮助