Is there any reason, why in the resources folder we have two folders in which we can define colors? (according to android developer page http://developer.android.com/guide/topics/resources/providing-resources.html#ResourceTypes).
This is the quote from android developer page:
values/
XML files that contain simple values, such as strings, integers, and colors.color/
XML files that define a state list of colors. See Color State List Resource
Is there any difference between Colors stored in res/colors and res/values? Which one is more preferable?
See Color State List Resource
Did you follow that link? http://developer.android.com/guide/topics/resources/color-list-resource.html
I think it answers your question.
By location,
res/color/
Is for the resource that is compiled to datatype Resource pointer to a
ColorStateList
.
A ColorStateList
is an object you can define in XML that you can apply as a color, but will actually change colors, depending on the state of the View object to which it is applied.
syntax:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android" > <item android:color="hex_color" android:state_pressed=["true" | "false"] android:state_focused=["true" | "false"] android:state_selected=["true" | "false"] android:state_checkable=["true" | "false"] android:state_checked=["true" | "false"] android:state_enabled=["true" | "false"] android:state_window_focused=["true" | "false"] /> </selector>
res/values/
If you want to provide a static color resource, use a simple Color value.
android:drawable="@color/green"
).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