Change default color settings bar .net MAUI

Fran3001 1 Reputation point
2022-07-07T17:13:17.937+00:00

HI,

I'm a begginer on platform .net MAUI and I would like to change the default color on the settings bar above the app :

218655-image.png

It's the .net MAUI purple by default. I would like it to be in white.

I found a way to change it but I don't think it's the best way to do so: I change directly the line

<color name="colorPrimary">#FFFFFF</color>

in Project->Platforms->Android->Resources->values->colors.xml

It worked but I don't see anymore the battery level, the clock as it's in white.. :

218696-image.png

Is there a better way to change this color ?
Is there a way to force the battery level, the clock in black to see them even when the background is white ?

Thanks for all !

.NET MAUI
.NET MAUI
A Microsoft open-source framework for building native device applications spanning mobile, tablet, and desktop.
2,750 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Leon Lu (Shanghai Wicresoft Co,.Ltd.) 66,561 Reputation points Microsoft Vendor
    2022-07-08T07:35:29.9+00:00

    Hello,​

    Is there a better way to change this color?

    No, it is the easiest way to change the color of status bar of android in MAUI.

    Is there a way to force the battery level, the clock in black to see them even when the background is white?

    Yes, you can change the color of battery level to grey (Native Android only allow to set grey or white).

    Please open your MainActivity.cs, override OnCreate method.

    For Android 11 or later, please use WindowInsetsController to set SystemBarsAppearance change the battery level color.

       if (Build.VERSION.SdkInt >= BuildVersionCodes.R)  
       {  
                   Window.InsetsController?.SetSystemBarsAppearance((int)WindowInsetsControllerAppearance.LightStatusBars, (int)WindowInsetsControllerAppearance.LightStatusBars);  
       }  
    

    For Android 6 to android 10, please use set SystemUiVisibility to change it.

       if(Build.VERSION.SdkInt >= BuildVersionCodes.M && Build.VERSION.SdkInt < BuildVersionCodes.R)  
       {  
                   Window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar;  
       }  
    

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.

    3 people found this answer helpful.

  2. abdulkan 10 Reputation points
    2023-01-22T12:22:53.09+00:00

    Use community toolkit. [https://youtu.be/dWj0PdImH10

    2 people found this answer helpful.
    0 comments No comments