3

In Xamarin.Forms app in MainActivity.cs I set immersive sticky mode:

    protected override void OnCreate(Bundle bundle)
    {
        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        base.OnCreate(bundle);
        Xamarin.Forms.Forms.Init(this, bundle);
        SetFullscreen();
        LoadApplication(new App());
    }

    void SetFullscreen()
    {
        var uiOptions = (int)Window.DecorView.SystemUiVisibility;
        uiOptions |= (int)SystemUiFlags.LowProfile;
        uiOptions |= (int)SystemUiFlags.Fullscreen;
        uiOptions |= (int)SystemUiFlags.HideNavigation;
        uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
        Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
        Window.SetFlags(WindowManagerFlags.KeepScreenOn, WindowManagerFlags.KeepScreenOn);
    }

When a page with an Entry (input box) and the keyboard comes up, it goes out of immersive mode and all system bars become visible. When keyboard is hidden, all bars stay visible.

Also using Acr.UserDialogs with ShowLoading().

How to stay in immersive mode all the time? Or how to return to immersive mode when closing the keyboard, and when calling HideLoading() of UserDialogs?

1 Answers1

2

I believe what you're looking for is the IOnSystemUiVisibilityChangeListener interface.

Create a your listener:

class SystemUiVisibilityChangeListener : Java.Lang.Object, View.IOnSystemUiVisibilityChangeListener
    {
        public void OnSystemUiVisibilityChange([GeneratedEnum] StatusBarVisibility visibility)
        {
            if (visibility == StatusBarVisibility.Visible)
            {
                //your code here
            }
        }
    }

And attach it to your decor view:

View decorView = Window.DecorView;
decorView.SetOnSystemUiVisibilityChangeListener(new SystemUiVisibilityChangeListener());
var uiOptions = (int)decorView.SystemUiVisibility;
...

If this does not work you may have to explore listening for the keyboard to hide; here is some research to get you started How to capture the "virtual keyboard show/hide" event in Android?

Matthew Andrews
  • 437
  • 1
  • 5
  • 16