1. 程式人生 > >Android隱藏和顯示虛擬導航欄

Android隱藏和顯示虛擬導航欄

隱藏導航欄

    /**
     * 隱藏虛擬按鍵,並且全屏
     */
    public static void hideBottomNav(Activity activity) {
       View decorView = activity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(0);
        int uiOptions = View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY | View.SYSTEM_UI_FLAG_FULLSCREEN | 
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN;
        decorView.setSystemUiVisibility(uiOptions);
    }

顯示導航欄

     /**
      * 重新顯示導航欄和狀態列
      */
    public static void showBottomNav(Activity activity) {
       View decorView = activity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(0);
    }

沉浸式狀態下顯示導航欄

     /**
      *沉浸式全屏狀態下,顯示導航欄和狀態列
      */
    public static void showBottomNav(Activity activity) {
       View decorView = activity.getWindow().getDecorView();
        decorView.setSystemUiVisibility(0);
        decorView .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | 
        View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
    }