For API level 35 in MAUI StatusBarColor and NavigationBarColor is always set to White

Faiz Quraishi 145 Reputation points
2024-12-14T16:46:41.96+00:00

Hi Team,

I am using Visual Studio 2022 with latest version and MAUI API Level 35

I have written below code in MainActivity.cs for changing StatusBarColor and NavigationBarColor

Its working till API level 34 fine but its Always set White Colour when using API level 35 .

Will Some one help in this regard to set my desired colour for API level 35

protected override void OnCreate(Bundle? savedInstanceState)

{

base.OnCreate(savedInstanceState);

//below code is to set navigation bar and status bar color to Yellow

if (Window is not null)

{

    try

    {

        //Window.SetStatusBarColor(Android.Graphics.Color.Rgb(227, 174, 9));//YellowDark--its done through comunity toolkit

        //Window.SetNavigationBarColor(Android.Graphics.Color.Rgb(227, 174, 9));//Yellow

        if (Microsoft.Maui.Controls.Application.Current is not null)

        {

            var colorYellow = (Color)Microsoft.Maui.Controls.Application.Current.Resources["Yellow"];

            var androidyellowColor = colorYellow.ToPlatform();

            var colorYellowdark = (Color)Microsoft.Maui.Controls.Application.Current.Resources["Yellowdark"];

            var androidYellowdarkColor = colorYellowdark.ToPlatform();

            Window.SetStatusBarColor(androidYellowdarkColor);//yellowDark

            Window.SetNavigationBarColor(androidyellowColor);//yellow

            

        }

    }

    catch

    { }

}

}

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
3,852 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Graham McKechnie 431 Reputation points
    2024-12-15T21:53:13.49+00:00

    Both SetStatusBarColor and SetNavigationBarColor are deprecated and removed in Android 15. They still work for Android 14 and lower but not Android 15. All part of going Edge-to-Edge.

    You might want to use something like the following. Add an else to each section to use SetStatusBarColor and SetNavigationBarColor if you want the old behaviour for devices less than 15.

    private void SetSystemBarsAppearance()

    {

    WindowInsetsControllerCompat windowInsetsController = new(Window!, Window!.DecorView);

    if (!IsNightModeActive())

    {

    if (OperatingSystem.IsAndroidVersionAtLeast(35))

    {

    windowInsetsController.AppearanceLightStatusBars = true;

    windowInsetsController.AppearanceLightNavigationBars = true;

    }

    }

    else

    {

    if (OperatingSystem.IsAndroidVersionAtLeast(35))

    {

    windowInsetsController.AppearanceLightStatusBars = false;

    windowInsetsController.AppearanceLightNavigationBars = false;

    }

    }

    }

    If you want to see a working example (Android only) check the BooksFragment and the README in the following project https://github.com/gmck/NavigationGraph9Net9

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.