Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Xamarin forms: Customize Android Material style status bar color

I have enabled Material theme on my Xamarin.Forms project with the following code, but on Android (Lollipop and Marshmallow) the top status bar (where the clock, signal, battery, etc.. are located) doesn't change. It remains always black. I've already read lot of forums and blogs, tried lot of combination but I'm not able to get this status bar colored as I want.

MainActivity.cs

[Activity(Theme = "@style/MyTheme", Label = "MyApp", Icon = "@drawable/AppIcon", ScreenOrientation = ScreenOrientation.Portrait, ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]

values-v21/style.xml

<resources>
  <style name="MyTheme.Splash" parent="android:Theme.Material.Light">    
    <item name="android:windowBackground">@drawable/SplashScreen</item>
    <item name="android:windowNoTitle">true</item>
  </style>
  <style name="MyTheme" parent="android:Theme.Material.Light">
    <item name="android:windowDrawsSystemBarBackgrounds">false</item>
    <item name="android:colorPrimary">@color/Brand</item>
    <item name="android:textColorPrimary">@color/White</item>
    <item name="android:statusBarColor">@color/BrandDark</item>
    <item name="android:colorPrimaryDark">@color/BrandDark</item>
    <item name="android:colorAccent">@color/Brand</item>
    <item name="android:textColor">@color/Brand</item>    
  </style>  
</resources>

values/colors.xml

<resources>  
  <color name="SplashBackground">#f78b2b</color>
  <color name="Brand">#f78b2b</color>
  <color name="BrandDark">#e47108</color>
  <color name="White">#ffffff</color>
</resources>

Thanks for any help!

like image 993
Stefano Avatar asked Jan 06 '23 05:01

Stefano


1 Answers

You should follow this Tutorial to get success.

Basically you have to use FormsAppCompatActivity instead of FormsApplicationActivity and Theme.AppCompat.Light.NoActionBar instead of Theme.Material.Light.

like image 191
Sven-Michael Stübe Avatar answered Apr 29 '23 13:04

Sven-Michael Stübe