时间:2021-01-15 11:12:50 | 栏目: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); } } }