Search code examples
c#xamarin.formsxamarin.androidfullscreenstatusbar

After exiting fullscreen in Xamarin Forms Android app, status bar overlaps page


I have an app that switches between full screen (without a status bar and restricted to landscape orientation) and regular (with status bar and no orientation restriction).

I am using a service dependency to call a method on the MainActivity with a boolean flag.

I have used two different methods for toggling the full screen setting: setting Window.DecorView.SystemUiVisibility and adding/clearing flags on Window. In the below code the second approach is commented out:

                if (fullScreenOn)
                {
                    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(
                        SystemUiFlags.Fullscreen
                        | SystemUiFlags.HideNavigation
                        | SystemUiFlags.Immersive
                        | SystemUiFlags.ImmersiveSticky
                        | SystemUiFlags.LowProfile
                        | SystemUiFlags.LayoutStable
                        | SystemUiFlags.LayoutHideNavigation
                        | SystemUiFlags.LayoutFullscreen
                    );

                    //Window.AddFlags(WindowManagerFlags.Fullscreen);

                    RequestedOrientation = ScreenOrientation.Landscape;
                }
                else
                {
                    Window.DecorView.SystemUiVisibility = (StatusBarVisibility)(
                        SystemUiFlags.LayoutStable
                        | SystemUiFlags.LayoutHideNavigation
                        | SystemUiFlags.LayoutFullscreen
                    );

                    //Window.ClearFlags(WindowManagerFlags.Fullscreen);

                    RequestedOrientation = ScreenOrientation.Unspecified;
                }

I have tried calling the dependency method from different places: OnAppearing() and OnDisappearing() in full screen pages, in all pages, just OnAppearing() in all pages, and also (not in the same build) from my navigation code when opening a new page or falling back to an existing one.

The app starts in a normal page and it all works until after viewing one of the full screen pages and returning to a normal page when the status bar comes back, but the page uses the full height of the screen and is overlapped as a result.

There's a secondary annoyance which is that even when going from one full screen page to another, the status bar pops in and out.

The iOS version of the app doesn't have either of these problems. Obviously, it uses a different implementation in it's dependency method.

Edit

I have created a minimal app which reproduces the main problem at https://github.com/aptwebapps/StatusBarBug. Interestingly, it does NOT suffer from the annoyance of the status bar popping in and out when moving between two full screen pages.


Solution

  • Well, I solved it using clearing the flag with device specific code.

    MainActivity.Instance.Window.ClearFlags(WindowManagerFlags.Fullscreen);
    

    I the app navigates to specific page, I've used platform specific code:

    MainActivity.Instance.RequestedOrientation = ScreenOrientation.Landscape;
    

    and while exit I've set it back to the portrait. But my page was adding the flag for full Screen using AddFlags() method in Android.

    Hope it helps to others who face the similar issue.