Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to completely exit from Immersive full screen mode?

I would like to implement a button to enable/disable the immersive full screen mode. I'm using those methods but the showSystemUI only shows quickly and hide again...

How to completely exit from immersive mode?

My methods:

// This snippet hides the system bars.
    @SuppressLint("NewApi")
    private void hideSystemUI() {
        try{
            // Set the IMMERSIVE flag.
            // Set the content to appear under the system bars so that the content
            // doesn't resize when the system bars hide and show.
            mDecorView.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 // hide nav bar
                            | View.SYSTEM_UI_FLAG_FULLSCREEN // hide status bar
                            | View.SYSTEM_UI_FLAG_IMMERSIVE);
        }catch(Exception e){
            getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN);
        }
    }

    // This snippet shows the system bars. It does this by removing all the flags
    // except for the ones that make the content appear under the system bars.
    @SuppressLint("NewApi")
    private void showSystemUI() {
        try{
            mDecorView.setSystemUiVisibility(
                    View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                            | View.SYSTEM_UI_FLAG_LAYOUT_HIDE_NAVIGATION
                            | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
        }catch(Exception e){
            getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);

            mDecorView.setVisibility(View.GONE);
            mDecorView.setVisibility(View.VISIBLE);
            WindowManager.LayoutParams attrs = getWindow().getAttributes();
            attrs.flags |= WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN | WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS;
            getWindow().setAttributes(attrs);
            mDecorView.setPadding(0, getStatusBarHeight(), 0, 0);
        }
    }

How to make the content appear under the system bars again?

like image 750
Felipe Porge Xavier Avatar asked Feb 10 '14 00:02

Felipe Porge Xavier


People also ask

How do I change full screen mode to normal mode?

Press and hold the "Ctrl key along with Shift key and press the J" key in the keyboard to toggle between the fullscreen mode and the normal view mode.

What is immersive full screen?

Android 4.4 (API Level 19) introduces a new SYSTEM_UI_FLAG_IMMERSIVE flag for setSystemUiVisibility() that lets your app go truly "full screen." This flag, when combined with the SYSTEM_UI_FLAG_HIDE_NAVIGATION and SYSTEM_UI_FLAG_FULLSCREEN flags, hides the navigation and status bars and lets your app capture all touch ...

How do I turn off immersive mode on Android?

Non-sticky (normal) immersive mode — A user can exit immersive mode, by swiping in the system bars. Sticky immersive mode — A user can temporarily exit immersive mode by swiping in the system bars. Immersive mode is automatically re-entered after a short time (few seconds).


2 Answers

Calling setSystemUiVisibility() with View.SYSTEM_UI_FLAG_VISIBLE clears all flags:

getWindow().getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_VISIBLE);
like image 173
Philipp E. Avatar answered Nov 01 '22 22:11

Philipp E.


What worked for me is the following:

View decorView = activity.getWindow().getDecorView();
decorView.setSystemUiVisibility(0);

I might be wrong but it seems like calling setSystemUiVisibility with 0 clears the flags which were previously applied.

like image 20
guy.gc Avatar answered Nov 01 '22 22:11

guy.gc