4
I was studying a little about the Android layout guidelines as:
So I tried to customize my Theme, thus:
<resources>
<!-- inherit from the material theme -->
<style name="AppTheme" parent="android:Theme.Material">
<!-- Main theme colors -->
<!-- your app branding color for the app bar -->
<item name="android:colorPrimary">@color/primary</item>
<!-- darker variant for the status bar and contextual app bars -->
<item name="android:colorPrimaryDark">@color/primary_dark</item>
<!-- theme UI controls like checkboxes and text fields -->
<item name="android:colorAccent">@color/accent</item>
</style>
</resources>
But the attributes, android:colorPrimary
, android:colorPrimaryDark
and android:colorAccent
, is only available for recent versions of Android (API 21+), which is currently not mine target.
So I took another route, to customize the components manually. So I tried to set the color of the Statusbar, with the method setStatusBarColor(int color)
, only this is also not available for versions prior to API 21.
Questions:
- Is there any way to set a solid color for Statusbar, for Android API 21- (Be it XML, or code)?
- Is there an Appcompat, which provides compatibility of the themes "Material" version smaller than API 21?
- There is some other way to get this result, for Android API 21-?
Important remarks
- Man
minTarget
is API 14.
Have you read this part? http://developer.android.com/training/material/compatibility.html
– Lucas Santos
@Lucassantos, worse than I had not seen. Hehe. I am creating a test project, to try to implement it. Thanks for the tip.
– Fernando Leal
sure will work. I implemented in my project and it worked. You are welcome.
– Lucas Santos
@Lucassantos, in my test project even worked, but still, did not change the color of the Statusbar as cited here, where the color of the Statusbar is to be the
colorPrimaryDark
, I’m running on an Android 4.2, and the Statusbar I’m still black, even try set withcolorPrimaryDark
in thestyle
with blue. Is this the correct behavior? Note: Actionbar changed color as expected.– Fernando Leal
Fernando, the color of Statusbar is only changed with the attribute
colorPrimaryDark
on SDK 21, or using Tinted/Translucent Statusbar on Android 19. Out of this there is no way to change the color...– Wakim
@Wakim, I get it, so actually the compatibility API doesn’t make this behavior consistent for all versions of Android, it only allows you to use it where it’s allowed, in this case, only in API 21+, and still keep it running without the Feature, for smaller versions. Right?
– Fernando Leal
Exactly, coloring the Status Bar does not have compatibility at all, but other properties such as
colorPrimary
andaccentColor
have paper, but thecolorPrimaryDark
only in version 21+.– Wakim
@Fernando I had a similar problem than yours. I had to change the color of the Ratingbar stars but it was only available for equal/higher versions than Lollipop. I ended up having to resort to libraries on Github to change the color and be compatible.
– Daniela Morais