Android教程網
  1. 首頁
  2. Android 技術
  3. Android 手機
  4. Android 系統教程
  5. Android 游戲
 Android教程網 >> Android技術 >> 關於Android編程 >> Android 中隱藏虛擬按鍵的方法實例代碼

Android 中隱藏虛擬按鍵的方法實例代碼

編輯:關於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 中隱藏虛擬按鍵的方法實例代碼,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對本站網站的支持!

  1. 上一頁:
  2. 下一頁:
熱門文章
閱讀排行版
Copyright © Android教程網 All Rights Reserved