Reputation: 1024
I am tryingo to set the status bar color on Android version of my xamarin forms project.
using:
Window.SetStatusBarColor(Resources.GetColor(Resource.Color.colorPrimary));
I have achieved the expected color, but instruction seem deprecated.
To avoid future crashed, How I can actualice the instruction?
Thanks in advance
Upvotes: 0
Views: 161
Reputation: 10346
you can change the color of the status bar using the new window.setStatusBarColor method introduced in API level 21.
Changing the color of status bar also requires setting two additional flags on the Window; you need to add the FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag and clear the FLAG_TRANSLUCENT_STATUS flag.
Window window = activity.getWindow();
// clear FLAG_TRANSLUCENT_STATUS flag:
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
// add FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS flag to the window
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
// finally change the color
window.setStatusBarColor(ContextCompat.getColor(activity, R.color.my_statusbar_color));
Here is the same thread that you can take a look: How to change the status bar color in android
Upvotes: 1
Reputation: 1267
You can set the color of your statusbar by applying color in your Styles.xml file, located under Resources -> values Folder.
<!-- colorPrimaryDark is used for the status bar -->
<item name="colorPrimaryDark">#1eb6ed</item>
Place this and it should work. Hope this may help you.
Upvotes: 0