I am developing an app for price verification on an Android device (OS version 7.1.2, API Level 25) using .NET MAUI RC3.
I have managed to make the status bar at the top disappear, as well as the .NET MAUI navigation bar, using Shell.NavBarIsVisible="False", however, I'm stuck at trying to disable the Android navigation bar at the bottom:
I have tried:
- NavigationPage.HasNavigationBar="False" in the
- NavigationPage.HasNavigationBar="False" in the
- NavigationPage.HasNavigationBar="False" in the
I have set this in the MainActivity, but it only removes the status bar at the top:
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
this.Window.AddFlags(Android.Views.WindowManagerFlags.Fullscreen);
}
}
The examples I found for hiding the navigation buttons all fail with syntax errors for various reasons:
- DecorView doesn't have the SetSystemUiVisibility method
- Android.Views.WindowManagerFlags doesn't have all the flags, such as "immersive", etc.
- WindowInsetsController is not available in API version 25
Any help would be appreciated.
Thanks,
Joerg.
CodePudding user response:
In MainActivity.cs:
using Android.Views;
...
public class MainActivity : MauiAppCompatActivity
{
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
this.Window.DecorView.SystemUiVisibility = (StatusBarVisibility)
(SystemUiFlags.ImmersiveSticky | SystemUiFlags.HideNavigation |
SystemUiFlags.Fullscreen | SystemUiFlags.Immersive);
}
}
I don't know which of those flags are needed, so I set them all.
Tested on a newer device. But should work fine on an API-25 device.
SystemUiVisibility
is marked as deprecated, but it still works.
If you set targetSdkVersion to API-31, you could add if-test to use WindowInsetsController where available. (Though it sounds like you have a specific device to run on, so not relevant to your situation.)
NOTE: targetSdkVersion and TargetFrameworkVersion do not have to be API-25; its fine if they are newer. Not sure how Maui is setting TargetFrameworkVersion. I think net6.0-android
is defaulting to API-31. Causing the warning you see.