Reputation: 1031
I'm developing an android application. I've defined a color in my resource as this:
<color name="toolbar_color">#ffcb00</color>
I've set this color as background in one of layouts such as 'Relative layout' and this color is shown correctly in most of android devices. BUT in samsung model S6310 android 4.2.1, I have a trouble. My color is not shown and instead of showing this color, android device shows transparent color. I've searched about this problem and the solution is using java code to set color for my layout. but I have many flavor builds and I don't want to change my java code.
Now I have 2 questions:
1- Why is this happening?
2- What's solution for this poblem?
Upvotes: 1
Views: 2828
Reputation: 534
Well to answer your question in simple terms
Why?
Well, this is simply the work of the Android Support Library. Android Support Library, now that it is backward compatible it should handle that. It should make the Application read those resources properly. But sometimes it doesn't. That mainly causes this. You can read more about how to set resources if something like that happens here and here.
Work-arounds Well there are many workarounds to this,
Set the resource colour directly in the XML instead of referencing to a resource.
Also you can set the resource colour or the resource using JAVA Code
.
It also states that adding
android {
...
defaultConfig {
...
vectorDrawables.useSupportLibrary = true
}
...
}
to the build.gradle solves the problem. Check here.
Anyway, better do it programatically.
Upvotes: 2
Reputation: 684
if its on android version you should check the version and set the color there
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLYBEAN) {
// Your required color
} else {
}
Hope this helps if its the problem with the android version.
Upvotes: 0