I\'m using the AppCompat-v7:21.0.0
support library for Android 5.0 Lollipop in Android Studio. My problem is that the Status Bar Color that can be changed by se
Changing the Status Bar color in pre-Lollipop(5.0) is not possible by setting colorPrimaryDark. See this article.
On older platforms, AppCompat emulates the color theming where possible. At the moment this is limited to coloring the action bar and some widgets.
I was working on an old app and trying to convert it to material style. The code and everything was fine however the only mistake I had that was hindering the status bar tinting on >= Lollipop devices was "TargetSDKVersion" in build.gradle. It was set to less then 21. I changed it to 21 and statusbar tinting started working.
Please read this: For this to take effect, the window must be drawing the system bar backgrounds with
android.view.WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS
but
android.view.WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS
must not be set (Source)
In case of you don't know how to add that flag:
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
In v22-appcompat
they (Android) have now added rendering of the status bar color in the android studio preview!
About time... Anyways, make sure your appcompat
library is updated to the latest version, which is v22.0.+.
Cheers!
This worked for me. Removed the status bar color from styles. Add flag and then put the color you want like so
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
getWindow().setStatusBarColor(getResources().getColor(R.color.your_color));
}
In my case, the culprit was jfeinstein10/SlidingMenu
library.
I replaced the library with Android navigation drawer
and now it displays status bar color correctly.