MAUI .NET Titlebar color Android

Olivier Manso 41 Reputation points
2022-08-17T07:39:54.677+00:00

Hello everyone,
is it possible to change the color of the text of the status banner that displays the times on Android?
I use Microsoft. Net MAUI.
Thank you for your help.

231889-status.png

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

Accepted answer
  1. Wenyan Zhang (Shanghai Wicresoft Co,.Ltd.) 25,521 Reputation points Microsoft Vendor
    2022-08-18T08:10:58.937+00:00

    Hello @Olivier Manso ,

    Native Android only allows the text in the status banner to be grey or white.

    For Android 11 or later, you can open your MainActivity.cs under Platform->Android, then override OnCreate method , and find the window to set SystemBarsAppearance. For Android 6 to android 10, please use set SystemUiVisibility to change it. In addition, you can set StatusBarColor so that the items on the bar can be read clearly.

    protected override void OnCreate(Bundle savedInstanceState)   
        { ...  
        Window.SetStatusBarColor(Android.Graphics.Color.Cyan);// change the  status bar color  
        if (Build.VERSION.SdkInt >= BuildVersionCodes.R)  
        {  
            Window.InsetsController?.SetSystemBarsAppearance((int)WindowInsetsControllerAppearance.LightStatusBars, (int)WindowInsetsControllerAppearance.LightStatusBars);  
        }  
        if (Build.VERSION.SdkInt >= BuildVersionCodes.M && Build.VERSION.SdkInt < BuildVersionCodes.R)  
        {  
            Window.DecorView.SystemUiVisibility = (StatusBarVisibility)SystemUiFlags.LightStatusBar;  
        }  
    }  
    

    Or you can do this in MainPage, please try using Microsoft.Maui.ApplicationModel, and find the Window by Platform.CurrentActivity.Window, then set SystemBarsAppearance

    #if ANDROID   
          
                  Platform.CurrentActivity.Window.SetStatusBarColor ....  
                  Platform.CurrentActivity.Window.InsetsController?.SetSystemBarsAppearance...  
      #endif  
    

    Best Regards,
    Wenyan Zhang


    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.


0 additional answers

Sort by: Most helpful