Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between res/color and res/values/colors.xml in Android resources folder

Tags:

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?

like image 768
Marek Avatar asked Jun 06 '13 00:06

Marek


2 Answers

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.

like image 64
Aurand Avatar answered Sep 28 '22 08:09

Aurand


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.

  • That is a color value defined in XML, specified with an RGB value and alpha channel.
  • You can use a color resource any place that accepts a hexadecimal color value.
  • You can also use a color resource when a drawable resource is expected in XML (for example, android:drawable="@color/green").
like image 43
TT-- Avatar answered Sep 28 '22 09:09

TT--