I'm wondering how to change the StatusBar color dependent on the current active Fragment (on 5.0 Lollipop). Currently, I change the ActionBar color dependent on the Fragment I am in, but now I want the StatusBar color to change as well - in order to look nice on Lollipop devices.
I've tried using setStyle to programmatically change the theme depending on the fragment, but it doesn't seem to be changing the status bar color.
Any ideas would be appreciated!
Have you tried to change the color of the status bar using Window.setStatusBarColor
? For example, you can do the following to change the status bar color to red programmatically.
getWindow().setStatusBarColor(Color.RED);
The documentation of setStatusBarColor
can be found here. You can also read the documentation on how to Customize the Status Bar.
Note: This method only works at Lollipop or above.
If you are seeing an unexpected color, make sure the integer value you are passing is a color integer and not a resource ID.
getWindow().setStatusBarColor(getResources().getColor(R.color.custom_color)); // RIGHT
getWindow().setStatusBarColor(R.color.custom_color); // WRONG
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With