Using new IMMERSIVE mode in android kitkat

后端 未结 6 696
说谎
说谎 2020-12-14 01:56

I want to make an activity to go into IMMERSIVE mode and hide top and buttom system bars as soon as it starts.

In developers site of android they say I should use

6条回答
  •  不思量自难忘°
    2020-12-14 02:55

    You can create global function to go into immersive mode like:

    public static void enableImmersiveMode(final View decorView) {
            decorView.setSystemUiVisibility(setSystemUiVisibility());
            decorView.setOnSystemUiVisibilityChangeListener(new View.OnSystemUiVisibilityChangeListener() {
                @Override
                public void onSystemUiVisibilityChange(int visibility) {
                    if ((visibility & View.SYSTEM_UI_FLAG_FULLSCREEN) == 0) {
                        decorView.setSystemUiVisibility(setSystemUiVisibility());
                    }
                }
            });
        }
    
    
    public static int setSystemUiVisibility() {
            return View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                    | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
                    | View.SYSTEM_UI_FLAG_FULLSCREEN
                    | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;
     }
    

    Above code will also control system UI visibility change. Hope this will help you.

提交回复
热议问题