Implement Full-Screen Mode in .NET MAUI Apps

This guide explains how to implement full-screen mode in .NET MAUI apps on Android and Windows, covering different Android versions and code examples.

  1. Android
    For Android 10 and above, override the OnCreate method in the MainActivity.cs file. Refer to the Android official documentation.

    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    protected override void OnCreate(Bundle? savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        WindowInsetsControllerCompat windowInsetsController = WindowCompat.GetInsetsController(Window, Window.DecorView);
        // Set the behavior for showing the status bar by swiping
        windowInsetsController.SystemBarsBehavior = WindowInsetsControllerCompat.BehaviorShowTransientBarsBySwipe;
        // Hide the status bar
        windowInsetsController.Hide(WindowInsetsCompat.Type.SystemBars());
    }
    

    For Android 12, override the OnCreate method in the MainActivity.cs file.

    1
    2
    3
    4
    5
    6
    7
    8
    
    protected override void OnCreate(Bundle? savedInstanceState)
    {
        base.OnCreate(savedInstanceState);
        // Full-screen display (hides the top status bar but not the bottom navigation bar)
        Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
        // Hide the bottom navigation bar (can be shown by swiping up)
        Window.DecorView.SystemUiFlags = SystemUiFlags.HideNavigation;
    }
    

    Add the following code in the MainActivity.cs file. If the bottom navigation bar is not needed, you can enable the “Hide Status Bar” option in Settings > Accessibility (Android 10).

     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    
    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());
                    wicController.Hide(WindowInsets.Type.SystemOverlays());
                    wicController.Hide(WindowInsets.Type.StatusBars());
                    wicController.Hide(WindowInsets.Type.MandatorySystemGestures());
                    wicController.Hide(WindowInsets.Type.CaptionBar());
                }
    #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();
    }
    
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    
    protected override void OnCreate(Bundle bSavedInstanceState)
    {
        base.OnCreate(bSavedInstanceState);
        SetWindowLayout();
    }
    
    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());
                    wicController.Hide(WindowInsets.Type.StatusBars());
                    wicController.Hide(WindowInsets.Type.MandatorySystemGestures());
                    wicController.Hide(WindowInsets.Type.CaptionBar());
                }
    #pragma warning restore CA1416
            }
            else
            {
    #pragma warning disable CS0618
                Window.DecorView.SystemUiVisibilityChange += DecorView_SystemUiVisibilityChange;
                Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
    
                Window.DecorView.SystemUiFlags = (SystemUiFlags.HideNavigation);
    #pragma warning restore CS0618
            }
        }
    }
    
    private void DecorView_SystemUiVisibilityChange(object? sender, Android.Views.View.SystemUiVisibilityChangeEventArgs e)
    {
        Window.SetFlags(WindowManagerFlags.Fullscreen, WindowManagerFlags.Fullscreen);
        Window.DecorView.SystemUiFlags = (SystemUiFlags.HideNavigation);
    }
    
Built with Hugo
Theme Stack designed by Jimmy