Forum Xamarin.Forms

How to set windowLightStatusBar in Xamarin.Forms (Android)?

I want to use a light background for the status bar and for better visibility I need to have dark status bar icons. Setting the background color works fine, but switching to dark icons with setting windowLightStatusBar to true does not work.

If I try the same with a Xamarin.Android app this works without a problem. TargetFramework ist Android 7.1 (API Level 25) for each.

This is how my MainTheme in style.xml looks like:

  <style name="MainTheme" parent="Theme.AppCompat.Light">
    <item name="windowNoTitle">true</item>
    <item name="windowActionBar">false</item>
    <item name="colorPrimary">#0000ff</item>
    <item name="colorPrimaryDark">#dddddd</item>
    <item name="android:statusBarColor">#ff0000</item>
    <item name="android:windowLightStatusBar">true</item>

    <item name="android:colorAccent">#FF4081</item>
    <item name="android:windowActionModeOverlay">true</item>
  </style>

But it results in this:

Obviously items with android: are ignored. But I can't compile statusBarColor and windowLightStatusBar without it.

And this is how it should look like (attempt in Xamarin.Android):

Can anybody tell me how to achieve this or what I'm doing wrong, please?

Answers

  • NMackayNMackay GBInsider, University admin

    I posted a sample here on how you can change the status bar color

    https://forums.xamarin.com/discussion/103665/xamarin-forms-set-android-in-light-theme#latest

  • SteveTSteveT USMember

    @NMackay: Thank you for your answer, but my problem is setting the status bar icons to dark gray (like second screenshot with Xamarin.Android app). I know changing the status bar color works fine by setting colorPrimaryDark.

  • SteveTSteveT USMember

    I the meantime I've found out that the items with android: are not ignored. They just seem to be overwritten in the process of loading:

    After setting a breakpoint in MainActivity.OnCreate, I recognized that the status bar did become red (#ff0000, like defined with android:statusBarColor) and the icons are dark. But after continue the status bar will be set to light gray (#dddddd; like defined with colorPrimaryDark) and the icons become white again.

    Any ideas what is causing this "overwriting"?

  • NMackayNMackay GBInsider, University admin

    Looking a bit further into this apparently it's supposed to be white according to the Android styling guidelines
    http://www.androiddocs.com/design/style/iconography.html

    "Notification icons must be entirely white. Also, the system may scale down and/or darken the icons."

    There's a few workarounds suggested here but they are very API level dependant if they work....
    https://stackoverflow.com/questions/30075827/android-statusbar-icons-color

  • SteveTSteveT USMember
    edited September 2017

    But "Notification icons must be entirely white..." refers to new icons provided by the app. What I want is, that "the system may scale down and/or darken the (existing) icons."

    This guideline was introduced with Android L (5.0, API 21). But with Android M (6.0, API 23) they introduced windowLightStatusBar (unable to post a link) which should darken the icons.

    As mentioned this actually works in a Xamarin.Android app like expected, but I can't get it to work properly in a Xamarin.Forms app.

  • NMackayNMackay GBInsider, University admin

    @SteveT

    Let us know if you find a solution, thanks.

Sign In or Register to comment.