Corrado's Blog 2.0

Online thoughts of a technology funatic

Xamarin.Android Status bar color not set

Not a very descriptive title, but good for search engines Smile

The problem: You’re using Xamarin.Android.Support.v7.AppCompat in order to have Material Design’s Toolbar available also devices running o pre-Lollipop (v.21) releases.

You added a reference to the library:

image

Added the style:

<style name="ParentMaterialTheme" parent="Theme.AppCompat.Light.NoActionBar"> <item name="colorPrimary">@color/colorPrimary</item> <item name="colorPrimaryDark">@color/colorPrimaryDark</item> <item name="colorAccent">@color/colorAccent</item> <item name="colorControlHighlight">#1ef1ab</item> <item name="colorButtonNormal">#f955f3</item> <item name="colorControlActivated">#0cf427</item> </style>

Added the entry into AndroidManifest.xml:

<application android:label="_02_StandaloneToolbar" android:theme="@style/MaterialTheme" />

Created the toolbar:

<android.support.v7.widget.Toolbar xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="wrap_content" android:background="@color/colorPrimary" android:minHeight="?attr/actionBarSize" android:theme="@style/ToolbarTheme" app:popupTheme="@style/PopupTheme" android:id="@+id/toolbar"> </android.support.v7.widget.Toolbar>

Included into Main.axaml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent"> <include android:layout_width="match_parent" android:layout_height="wrap_content" layout="@layout/toolbar"/> </RelativeLayout>

But when you run it, the status bar doesn’t follow colorPrimaryDark but it remains black Confused smile

image

 

Solution: add this line into Activity’s OnCreate method (yes, you have to use code)

this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);

And you’re done!

image