Search code examples
javaandroidfullscreenstatusbarandroid-fullscreen

How to re-show status bar after exiting full screen + Navigation bar won't go away after appearence


I have a video which is played in small-window with the option to go full screen. The issue is, however, the status bar and navigation bar hide/show does not work properly. I have tried almost all the solutions provided in Stackoverflow but none of them worked. This is my activity which is in the proper UI state:

Before Playing the video and going to full-screen

This is how I enter the full-screen:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
    getWindow().getDecorView().setSystemUiVisibility(
             View.SYSTEM_UI_FLAG_LAYOUT_STABLE
            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
            // Hide the nav bar and status bar
            | View.SYSTEM_UI_FLAG_HIDE_NAVIGATION
            | View.SYSTEM_UI_FLAG_FULLSCREEN);

This is how I exit the full screen:

getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
                | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION);

The first issue is when in the full-screen mode both status and navigation bar are properly hidden. However, with the first touch on the screen, the navigation bar will be visible but never hides again (I am using Leanback mode). It can be seen here:

Navigation bar won't go away after the first touch in full screen

The second issue is with the status bar. When the video is completed and full-screen mode is exited. The status bar overlaps and does not appear properly. Shown below:

Status bar not shown after exiting full screen


Solution

  • So finally found the answer worked for me:

    private void hideSystemUI() {
        getWindow().setFlags(WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS, WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS);
        getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().getDecorView().setSystemUiVisibility(
                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
    
        );
    }
    
    private void showSystemUI() {
        getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
        getWindow().getDecorView().setSystemUiVisibility(View.VISIBLE);
    }