Search code examples
c#androidmaui

Android app not in fullscreen even though the flags are set to be fullscreened


I'm still new to .NET MAUI, and I'm trying to make a simple FTP client app for my phone. However, I'm unable to set it to full screen.

I've set the flags, but whenever I test it on my local device, it refuses to full screen. Here's a screenshot:

enter image description here

Here's my MainActivity.cs the Android platform:

using Android.App;
using Android.Content.PM;
using Android.OS;
using Android.Views;
using AndroidX.Core.View;

namespace FTPBuddy
{
    [Activity(Theme = "@style/Maui.SplashTheme", MainLauncher = true, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation | ConfigChanges.UiMode | ConfigChanges.ScreenLayout | ConfigChanges.SmallestScreenSize | ConfigChanges.Density)]
    public class MainActivity : MauiAppCompatActivity
    {
        protected override void OnCreate(Bundle? savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            Window?.AddFlags(WindowManagerFlags.Fullscreen | WindowManagerFlags.LayoutInScreen);
            Window?.ClearFlags(WindowManagerFlags.ForceNotFullscreen);

            var controller = Window?.InsetsController;
            controller?.Hide(WindowInsets.Type.SystemBars());
        }
    }
}

If somebody could help solve this issue, that would be great, thanks!


Solution

  • You can try to use the following code to make your app full screen:

    public class MainActivity : MauiAppCompatActivity
        {
            protected override void OnCreate(Bundle? savedInstanceState)
            {
                base.OnCreate(savedInstanceState);
                Window.SetFlags(WindowManagerFlags.LayoutNoLimits, WindowManagerFlags.LayoutNoLimits);
                Window.Attributes.LayoutInDisplayCutoutMode = LayoutInDisplayCutoutMode.ShortEdges;
                Window.DecorView.SystemUiFlags =
                    (SystemUiFlags.ImmersiveSticky | SystemUiFlags.HideNavigation |
                     SystemUiFlags.Fullscreen | SystemUiFlags.Immersive);
    
            }
        }