Hide status bar on Android when using a modal page

AndrewHoffmanAndrewHoffman USUniversity ✭✭

I'm running into a problem on Android when hiding the status bar and showing a modal page. The problem is the modal page does not take up the full height of the screen as can be seen in the picture below. iOS does not have any problems.

My code to show/hide the status bar:

#if __IOS__
                UIKit.UIApplication.SharedApplication.SetStatusBarHidden(!status, false);
#else
                if (status)
                {
                    Droid.MainActivity.Instance.Window.ClearFlags(Android.Views.WindowManagerFlags.Fullscreen);
                }
                else
                {
                    Droid.MainActivity.Instance.Window.AddFlags(Android.Views.WindowManagerFlags.Fullscreen);
                }
#endif

I also attempted to hide the status bar upon app creation but still ran into the same problem with the modal pages. Can anybody point me in the right direction?

Posts

  • ClintStLaurentClintStLaurent USUniversity ✭✭✭✭✭

    Take a look at this thread from earlier today:
    https://forums.xamarin.com/discussion/104089/can-i-do-more-to-hide-navigation-that-this

    He does a good job of going into full Immersive Mode

  • AndrewHoffmanAndrewHoffman USUniversity ✭✭

    Ok, going off the thread posted above, i changed my code this:

    if (Android.OS.Build.VERSION.SdkInt >= Android.OS.BuildVersionCodes.Lollipop)
    {
            var stBarHeight = typeof(Xamarin.Forms.Platform.Android.FormsAppCompatActivity).GetField("statusBarHeight", BindingFlags.Instance | BindingFlags.NonPublic) ?? typeof(Xamarin.Forms.Platform.Android.FormsAppCompatActivity).GetField("_statusBarHeight", BindingFlags.Instance | BindingFlags.NonPublic);
             stBarHeight?.SetValue(Droid.MainActivity.Instance, 0);
     }
    
     var newUiOptions = (int)Android.Views.SystemUiFlags.LayoutStable;
     newUiOptions |= (int)Android.Views.SystemUiFlags.LayoutFullscreen;
     newUiOptions |= (int)Android.Views.SystemUiFlags.Fullscreen;
    
     Droid.MainActivity.Instance.Window.DecorView.SystemUiVisibility = (Android.Views.StatusBarVisibility)newUiOptions;
    

    It seems to work better with on exception. When the status bar disappears, it leaves a red rectangle. I can get rid of the rectangle by rotating device, but I don't want to force my users to do that. Is there way to update the layout so the red rectangle goes away without rotating?

Sign In or Register to comment.