First of all it's not a duplicate as in How to change the background color of android status bar
How do I change the status bar color which should be same as in navigation bar.
I want the status bar color to be same as the navigation bar color
First of all it's not a duplicate as in How to change the background color of android status bar
How do I change the status bar color which should be same as in navigation bar.
I want the status bar color to be same as the navigation bar color
Update:
Lollipop:
Added in API level 21
Android Lollipop brought with it the ability to change the color of status bar in your app for a more immersive user experience and in tune with Google’s
Material Design Guidelines
.Here is how you can change the color of the status bar using the new
window.setStatusBarColor
method introduced inAPI 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 theFLAG_TRANSLUCENT_STATUS
flag.Working Code:
Offcial developer reference : setStatusBarColor(int)
Example :material-design-everywhere
Chris Banes Blog- appcompat v21: material design for pre-Lollipop devices!
The
transitionName
for the view background will beandroid:status:background
.this is very easy way to do this without any Library: if the OS version is not supported - under kitkat - so nothing happend. i do this steps:
then i made this method:
also you need those both methods to get action Bar & status bar height:
then the only thing you need is this line to set status bar color:
Edit the colorPrimary in the colors.xml in Values to the color you want the Status Bar to be. For example:
Place this is your values-v21/styles.xml, to enable this on Lollipop:
Just create a new theme in res/values/styles.xml where you change the "colorPrimaryDark" which is the color of the status bar:
And modify the activity theme in AndroidManifest.xml to the one you want, on the next activity you can change the color back to the original one by selecting the original theme:
This is how your res/values/colors.xml should look like:
I had this requirement: Changing programmatically the status bar color keeping it transparent, to allow the Navigation Drawer to draw itself overlapping the trasparent status bar.
I cannot do that using the API
If you check here in stack overflow everyone before that line of code set the transparency of the status bar to solid with
I'm able to manage color and transparency of status bar like this:
Android 4: there's not much you can do, because you can't manage status bar color from the API ... the only thing you can do is to set the status bar as translucent and move a colored element of you UI under the status bar. To do this you need to play with
in your main layout. This allows you to draw you layout under the status bar. Then you need to play with some padding with the top of your main layout.
Android 5 and above: you have to define a style with
this allows the navigation drawer to overlap the status bar.
Then to change the color keeping the status bar transparent you have to set the status bar color with
where drawerLayout is defined like this