'How to set a ContentPage in MAUI full screen (or immersive)?
Is there a property to set for a page to be shown in full screen ?
(In Xamarin one would set Immersive mode for Android etc.)
Solution 1:[1]
For the Maui Project, you do not need to set the full screen in ContentPage again. Set the full screen in Android would work as well. You could add the code below in MainActivity.cs of Maui project.
protected override void OnCreate(Bundle savedInstanceState)
{
base.OnCreate(savedInstanceState);
Platform.Init(this, savedInstanceState);
this.Window.AddFlags(WindowManagerFlags.Fullscreen);
}
In ContentPage, it provides a easy way to hide the Bar to do the same thing with full screen via set the HasNavigationBar property to false.
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="MauiApp1.MainPage"
BackgroundColor="{DynamicResource SecondaryColor}"
NavigationPage.HasNavigationBar="False">
Solution 2:[2]
For Android change the MainActivity class to something like:
[Activity(ConfigurationChanges = ConfigChanges.Density |
ConfigChanges.Orientation |
ConfigChanges.ScreenLayout |
ConfigChanges.ScreenSize |
ConfigChanges.SmallestScreenSize |
ConfigChanges.UiMode,
LaunchMode = LaunchMode.SingleTop,
MainLauncher = true,
Theme = "@style/Maui.SplashTheme")]
public class MainActivity : MauiAppCompatActivity
{
private void SetWindowLayout()
{
if (Window != null) {
if (Build.VERSION.SdkInt >= BuildVersionCodes.R) {
#pragma warning disable CA1416
IWindowInsetsController wicController = Window.InsetsController;
Window.SetDecorFitsSystemWindows(false);
Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
if (wicController != null) {
wicController.Hide(WindowInsets.Type.Ime ());
wicController.Hide(WindowInsets.Type.NavigationBars());
}
#pragma warning restore CA1416
}
else {
#pragma warning disable CS0618
Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
Window.DecorView.SystemUiVisibility = (StatusBarVisibility) (SystemUiFlags.Fullscreen |
SystemUiFlags.HideNavigation |
SystemUiFlags.Immersive |
SystemUiFlags.ImmersiveSticky |
SystemUiFlags.LayoutHideNavigation |
SystemUiFlags.LayoutStable |
SystemUiFlags.LowProfile);
#pragma warning restore CS0618
}
}
}
protected override void OnCreate(
Bundle bSavedInstanceState)
{
base.OnCreate(bSavedInstanceState);
SetWindowLayout();
}
}
Note: I use a separate method (SetWindowLayout) because it is used elsewhere. You may not not need to.
for WinUI (UWP), I haven't found a solution yet. This used to work in the App.Xaml.cs file:
using Windows.UI.ViewManagement;
public App()
{
ApplicationView.PreferredLaunchWindowingMode = ApplicationViewWindowingMode.FullScreen;
InitializeComponent();
}
but now doesn't appear to.
Hope this helps, Loz.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Wendy Zang - MSFT |
| Solution 2 | LozCool |
