0

I wrote the following code to enter an activity to the immersive mode.

decorView = Window.DecorView;
var uiOptions = (int)decorView.SystemUiVisibility;
var newUiOptions = (int)uiOptions;
newUiOptions |= (int)SystemUiFlags.LowProfile;
newUiOptions |= (int)SystemUiFlags.Fullscreen;
newUiOptions |= (int)SystemUiFlags.HideNavigation;
newUiOptions |= (int)SystemUiFlags.Immersive;  
newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;
decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

This works perfectly and I get a perfect immersive mode.

Now the issue is, when I use the following code to exit the immersive mode, It exits the immersive mode but turns my status bar and navigation bar to white.

BEFORE IMMERSIVE MODE:

enter image description here

Status bar and Navigation are light

AFTER EXITING IMMERSIVE MODE:

enter image description here

To Exit immersive mode I am using the following code

decorView = Window.DecorView;
decorView.SystemUiVisibility = StatusBarVisibility.Visible;

I tried few other things, such as the following

How to completely exit from Immersive full screen mode?

https://developer.android.com/training/system-ui/immersive

They work but all with white status bar and navigation bar.

In Addition, yes I am using the LightStatusBar and LightNavigationBar but even setting that when exiting the immersive mode does not work such as

decorView = Window.DecorView;
var uiOptions = (int)decorView.SystemUiVisibility;
var newUiOptions = (int)uiOptions;
newUiOptions |= (int)SystemUiFlags.LightNavigationBar;
newUiOptions |= (int)SystemUiFlags.LightStatusBar;
decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

Anything I do, I just can't get the status bar and navigation bar back to normal after exiting the immersive mode

Any idea on this?

STYLES.XML

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    <!-- Customize your theme here. -->
    <item name="colorPrimary">@color/colorPrimary</item>
    <item name="colorPrimaryDark">@color/colorPrimaryDark</item>
    <item name="colorAccent">@color/colorAccent</item>

    <item name="android:windowNoTitle">true</item>    
    <item name="android:statusBarColor">#ffffff</item>    
    <item name="android:windowLightStatusBar">true</item>
    <item name="android:navigationBarColor">@color/colorPrimary</item>
    <item name="android:windowLightNavigationBar">true</item>
    <item name="android:actionBarStyle">@style/CustomActionBarStyle</item>
  </style>

  <style name="CustomActionBarStyle" parent="Theme.AppCompat.Light.NoActionBar">    
    <item name="android:titleTextStyle">@style/NoTitleText</item>
    <item name="android:subtitleTextStyle">@style/NoTitleText</item>
  </style>

  <style name="NoTitleText">
    <item name="android:textSize">0sp</item>
    <item name="android:textColor">#00000000</item>
  </style>

Cheers

Ali
  • 2,702
  • 3
  • 32
  • 54
  • Hello, could you please provide a demo for your question? I can't reproduce your problem, [it](https://developer.android.com/training/system-ui/immersive) works well on my phone. – Robbit May 08 '18 at 06:32
  • Hi, I found this [case](https://stackoverflow.com/questions/48660224/status-bar-is-white-when-entering-immersive-full-screen-mode), but I also can't reproduce his question, he has provided an answer for his question, maybe it will help you. And [here](https://stackoverflow.com/questions/32428700/status-bar-turns-white-and-does-not-show-content-behind-it) is about the white color problem. – Robbit May 08 '18 at 06:51
  • Hi Joe, I will create a demo app and will see if I can re-create the issue. I also updated the post to include my `styles.xml` as i think there is something in it causing the issue – Ali May 10 '18 at 02:12
  • Hi, so your application's min version is 27? – Robbit May 11 '18 at 06:15
  • Hi Joe, my application minimum version is API 21 (lollipop) – Ali May 11 '18 at 12:05

2 Answers2

1

If this might help someone, I found the solution after looking at this https://developer.xamarin.com/samples/monodroid/AdvancedImmersiveMode/ So basically, fully exit the immersive mode you need to set same UI options but with different values such as

Enter immersive mode

 decorView = Window.DecorView;
                var uiOptions = (int)decorView.SystemUiVisibility;
                var newUiOptions = (int)uiOptions;
                newUiOptions |= (int)SystemUiFlags.LowProfile;
                newUiOptions |= (int)SystemUiFlags.Fullscreen;
                newUiOptions |= (int)SystemUiFlags.HideNavigation;
                newUiOptions |= (int)SystemUiFlags.Immersive;
                // This option will make bars disappear by themselves
                newUiOptions |= (int)SystemUiFlags.ImmersiveSticky;
                decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions;

Exit immersive mode

decorView = Window.DecorView;
                var uiOptions = (int)decorView.SystemUiVisibility;
                var newUiOptions = (int)uiOptions;
                newUiOptions &= ~(int)SystemUiFlags.LowProfile;
                newUiOptions &= ~(int)SystemUiFlags.Fullscreen;
                newUiOptions &= ~(int)SystemUiFlags.HideNavigation;
                newUiOptions &= ~(int)SystemUiFlags.Immersive;                
                newUiOptions &= ~(int)SystemUiFlags.ImmersiveSticky;
                decorView.SystemUiVisibility = (StatusBarVisibility)newUiOptions; 

So basically the same options but using & along with ~ instead of OR

I hope this helps someone - The same code in the link is great to get more info on it.

Ali
  • 2,702
  • 3
  • 32
  • 54
0

In your styles.xml file, change this:

<item name="android:statusBarColor">#ffffff</item>

to this:

 <item name="android:statusBarColor">@color/colorPrimary</item>
Robbit
  • 4,300
  • 1
  • 13
  • 29