Monday, 26 April 2021

Keep immersive mode all over the app on Android, Xamarin.forms

I want to keep immersive mode all over the app on Android using Xamarin.forms. I have read few blogs and posts. This one works but only until I press an input text box or I scroll over the screen. I want to avoid this. This question debate my concern but I don't understand the solution. Maybe it is obsolete. My android device is 7.1 and this is my code on my .Android MainActivity, void OnCreate, void OnCreate:

public class MainActivity : global::Xamarin.Forms.Platform.Android.FormsAppCompatActivity{
    protected override void OnCreate(Bundle savedInstanceState){
        Xamarin.Essentials.Platform.Init(this, savedInstanceState);
        global::Xamarin.Forms.Forms.Init(this, savedInstanceState);

        TabLayoutResource = Resource.Layout.Tabbar;
        ToolbarResource = Resource.Layout.Toolbar;
        base.OnCreate(savedInstanceState);
        LoadApplication(new App());

        ImmersiveMode();
    }

    public override void OnRequestPermissionsResult(int requestCode, string[] permissions, [GeneratedEnum] Android.Content.PM.Permission[] grantResults){
        Xamarin.Essentials.Platform.OnRequestPermissionsResult(requestCode, permissions, grantResults);

        base.OnRequestPermissionsResult(requestCode, permissions, grantResults);
    }

    public void ImmersiveMode() {
        int uiOptions = (int)(Forms.Context as Activity).Window.DecorView.SystemUiVisibility;
        uiOptions |= (int)SystemUiFlags.Fullscreen;
        uiOptions |= (int)SystemUiFlags.HideNavigation;
        uiOptions |= (int)SystemUiFlags.ImmersiveSticky;
        (Forms.Context as Activity).Window.DecorView.SystemUiVisibility = (StatusBarVisibility)uiOptions;
    }
}

How could I resolve this? Could you be specific on where I should located the new code. I'm noob on Xamarin.Forms and it looks tricky for me. Thank you

Edit: this code:

this.Window.AddFlags(WindowManagerFlags.Fullscreen); on the .Android MainActivity hides the Android bar with the wifi signal, time, bluetooth, etc.

Is there a line like that one to hide this android buttons?

enter image description here



from Keep immersive mode all over the app on Android, Xamarin.forms

No comments:

Post a Comment