android 隐藏虚拟按键 Android 中隐藏虚拟按键的方法实例代码
jiang547860818 人气:2想了解Android 中隐藏虚拟按键的方法实例代码的相关内容吗,jiang547860818在本文为您仔细讲解android 隐藏虚拟按键的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点: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 中隐藏虚拟按键的方法实例代码,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对网站的支持!
加载全部内容