Search code examples
androidfullscreenandroid-immersive

Immersive mode activity transition


I've successfully set the app in the immersive mode because I want to hide the status bar (on the top screen) and the navigation bar (on the bottom screen). The problem is that when the activity changes the bottom bar automatically arise and immediately after go down and disappear. I want to avoid this.

All activities have the style AppTheme.NoActionBar set in the manifest:

android:theme="@style/AppTheme.NoActionBar"

And in the OnCreate all have the following code:

getWindow().getDecorView().getViewTreeObserver().addOnGlobalLayoutListener(
                new ViewTreeObserver.OnGlobalLayoutListener() {
                    @Override
                    public void onGlobalLayout() { 
                 GlobalFunctions.setFullscreen(getWindow().getDecorView());
                    }
                });

Where this is the setFullscreen() function:

public static void setFullscreen(View decorView){
        int ui_Options = 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;
        decorView.setSystemUiVisibility(ui_Options);
    }

Should I set these attributes before the onCreate in the activity lifecycle? or there are other solutions? or I've implemented the immersive mode in the wrong way?


Solution

  • You don't need to set the global layout listener. Just invoke the setFullscreen function before super.onCreate()