Android隱藏虛擬選單(虛擬按鈕導航欄)
阿新 • • 發佈:2019-02-16
方法一:方法參考自http://blog.csdn.net/tian_di_yi_jian/article/details/62425096,方法如下:
/** * 隱藏虛擬按鍵,並且全屏 */ public static void hideBottomUIMenu(Activity activity) { //隱藏虛擬按鍵,並且全屏 if (Build.VERSION.SDK_INT > 11 && Build.VERSION.SDK_INT < 19) { // lower api View v = activity.getWindow().getDecorView(); v.setSystemUiVisibility(View.GONE); } else if (Build.VERSION.SDK_INT >= 19) { //for new api versions. View decorView = activity.getWindow().getDecorView(); int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN; decorView.setSystemUiVisibility(uiOptions);} }
方法二:通過反射找到setSystemUiVisibility方法,設定隱藏虛擬選單
private static final int SYSTEM_UI_FLAG_HIDE_NAVIGATION = // 1 | 2 | 4 | 0x200 | 0x400 | 0x00000100; 0x00000100 | 0x00000200 | 0x00000400 | 0x00000002 // hide nav bar | 0x00000004 // hide status bar | 0x00001000; private void hidSysNavigation() { if (Build.VERSION.SDK_INT > 10) { try{ View v = getWindow().getDecorView(); Method m = View.class.getMethod("setSystemUiVisibility", int.class); m.invoke(v, new Object[]{SYSTEM_UI_FLAG_HIDE_NAVIGATION}); //v.setSystemUiVisibility(SYSTEM_UI_FLAG_HIDE_NAVIGATION); } catch (Throwable e) { e.printStackTrace(); } } } @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // setContentView(R.layout.activity_full_screen); requestWindowFeature(Window.FEATURE_NO_TITLE); this.getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN); hidSysNavigation(); initView(); }