Change color of status bar in android apps programmatically

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 :

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(activity.getResources().getColor(R.color.my_statusbar_color));

Keep in mind that using this requires an API level of 21 at least.
The color my_statusbar_color needs to be defined in your color resources

One response to this entry

  • Sir I tried your code and it works perfect but same piece of code doesnt work for an activity which is chat activity…(i.e. one to one chat activity). I am using layer atlas message screen so is it something to do with that? Please send me your feedback..

    Reply / Quote

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

2017 All rights reserved | Powered by WordPress
Back to top
Theme by dynamicguru.com