Xamarin.Android Status bar color not set
Posted March 24th, 2016 . 4 Comments .
Not a very descriptive title, but good for search engines
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:
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
Solution: add this line into Activity’s OnCreate method (yes, you have to use code)
this.Window.AddFlags(WindowManagerFlags.DrawsSystemBarBackgrounds);
And you’re done!
4 Responses to “Xamarin.Android Status bar color not set”
RSS feed for comments on this post. TrackBack URL
Thanks! It works also with custom color changed from seeSharp.
Window.SetStatusBarColor(color);
Comment by Jan — 25/07/2016 @ 11:27
Thank you very much for your solution. Adding your line in “onCreate” method I solve my unbearable issue relating the property of android:windoTranslucentStatus.
If translucentStatus is setted to true the status bar is tinted, but in such case the toolbar overlap status bar.
But if it is setted to false the status bar isn’t tinted.
So by adding your line (AddFlags in oncreate method) and setting translucentstatus to false I solve my problem!!!
Thanks!
Comment by TuxJ — 29/09/2016 @ 12:13
thank you very match
you really saved my day
Comment by Mustafa — 25/02/2017 @ 18:49
Thanks For Ur Blog Helped Me Alot…..
Comment by Ali — 04/10/2017 @ 17:09