in my one Activity I change the Toolbar color using Palette
but on 5.0 devices using ActionBarActivity
the status bar
color is the color of my colorPrimaryDark
in my activity theme so I have 2 very different color and it does not look good.
I realize that in 5.0 you can use Window.setStatusBarColor()
but ActionBarActivity
does not have this.
so my question is in 5.0 how can I change the status bar color with ActionBarActivity
?
Applying
in
Theme.AppCompat.Light.DarkActionBar
didn't worked for me. What did the trick is , givingcolorPrimaryDark
as usual along withandroid:colorPrimary
in styles.xmland in setting
didn't had to set statusbar color in code .
I'm not sure I understand the problem.
I you want to change the status bar color programmatically (and provided the device has Android 5.0) then you can use
Window.setStatusBarColor()
. It shouldn't make a difference whether the activity is derived fromActivity
orActionBarActivity
.Just try doing:
Just tested this with
ActionBarActivity
and it works alright.Note: Setting the
FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
flag programmatically is not necessary if yourvalues-v21
styles file has it set already, via:Thanks for above answers, with the help of those, after certain R&D for xamarin.android MVVMCross application, below worked
Flag specified for activity in method OnCreate
For each MvxActivity, Theme is mentioned as below
My SplashStyle.xml looks like as below
And I have V7 appcompact referred.
I don't think the status bar color has been implemented in AppCompat yet. These are the attributes which are available:
(From \sdk\extras\android\support\v7\appcompat\res\values\attrs.xml)
Try this, I used this and it works very good with v21.
There are various ways of changing the status bar color.
1) Using the styles.xml. You can use the android:statusBarColor attribute to do this the easy but static way.
Note: You can also use this attribute with the Material theme.
2) You can get it done dynamically using the setStatusBarColor(int) method in the Window class. But remember that this method is only available for API 21 or higher. So be sure to check that, or your app will surely crash in lower devices.
Here is a working example of this method.
where primaryDark is the 700 tint of the primary color I am using in my app. You can define this color in the colors.xml file.
Do give it a try and let me know if you have any questions. Hope it helps.