Issue
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
Solution
Update:
Lollipop:
public abstract void setStatusBarColor (int color)
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 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.
Working Code:
import android.view.Window;
...
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));
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 be android:status:background
.
Answered By - codercat
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.