Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Immersive Mode showing blank space

Tags:

I'm trying to implement a fullscreen mode, but for Android 4.4 and up, it shows a blank space there:

BEFORE immersive mode(fullscreen)

enter image description here

and AFTER the toggleFullScreen(false);

enter image description here

as you can see, its doesn't remove it. Here's the code that I'm using to toggle it:

public void toggleFullscreen(boolean fs) {         if (Build.VERSION.SDK_INT >= 11) {             // The UI options currently enabled are represented by a bitfield.             // getSystemUiVisibility() gives us that bitfield.             int uiOptions = this.getWindow().getDecorView().getSystemUiVisibility();             int newUiOptions = uiOptions;             boolean isImmersiveModeEnabled =                     ((uiOptions | View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY) == uiOptions);             if (isImmersiveModeEnabled) {                 Log.i(getPackageName(), "Turning immersive mode mode off. ");             } else {                 Log.i(getPackageName(), "Turning immersive mode mode on.");             }              // Navigation bar hiding:  Backwards compatible to ICS.             if (Build.VERSION.SDK_INT >= 14) {                 newUiOptions ^= View.SYSTEM_UI_FLAG_HIDE_NAVIGATION;             }              // Status bar hiding: Backwards compatible to Jellybean             if (Build.VERSION.SDK_INT >= 16) {                 newUiOptions ^= View.SYSTEM_UI_FLAG_FULLSCREEN;             }              // Immersive mode: Backward compatible to KitKat.             // Note that this flag doesn't do anything by itself, it only augments the behavior             // of HIDE_NAVIGATION and FLAG_FULLSCREEN.  For the purposes of this sample             // all three flags are being toggled together.             // Note that there are two immersive mode UI flags, one of which is referred to as "sticky".             // Sticky immersive mode differs in that it makes the navigation and status bars             // semi-transparent, and the UI flag does not get cleared when the user interacts with             // the screen.             if (Build.VERSION.SDK_INT >= 18) {                 newUiOptions ^= View.SYSTEM_UI_FLAG_IMMERSIVE_STICKY;             }             getWindow().getDecorView().setSystemUiVisibility(newUiOptions);         } else {             // for android pre 11             WindowManager.LayoutParams attrs = getWindow().getAttributes();             if (fs) {                 attrs.flags |= WindowManager.LayoutParams.FLAG_FULLSCREEN;             } else {                 attrs.flags &= ~WindowManager.LayoutParams.FLAG_FULLSCREEN;             }             this.getWindow().setAttributes(attrs);         }          try {             // hide actionbar             if                     (this instanceof AppCompatActivity) {                 if (fs) getSupportActionBar().hide();                 else getSupportActionBar().show();             } else if                     (Build.VERSION.SDK_INT >= 11) {                 if (fs) getActionBar().hide();                 else getActionBar().show();             }         } catch (Exception e) {             e.printStackTrace();         }     } 
like image 799
user2582318 Avatar asked Dec 22 '15 04:12

user2582318


People also ask

What is immersive full screen?

The Fullscreen immersive app lets you enjoy the immersive mode in Android at its peak, and there are absolutely no hidden costs whatsoever. The app uses every possible pixel of your device and gives you an out of the world experience, especially when you are watching videos, reading books or playing games.

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

Please check that you don't have android:fitsSystemWindows="true" in your layout.

At least it solved my case - I had fitsSystemWindows on FrameLayout.

like image 123
Boris Treukhov Avatar answered Sep 22 '22 15:09

Boris Treukhov


I'm new here so I can't comment, but wanted to add something that got me so frustrated me about the above solution. I kept checking my activities and its fragments for android:fitsSystemWindows="true" and it was definitely not there, yet I kept having a gap at the bottom! I was going nuts! It couldn't be this hard to fix this simple thing!

Turns out it also showed up in the Navigation Drawer I added...so be sure to check all your XML!

like image 32
Jacky Tang Avatar answered Sep 23 '22 15:09

Jacky Tang