When I look at misc. Android tutorials and examples when it comes to specifying colors I very often see constants like @color/red
or @color/black
e
Is "colors.xml" added to your res/values folder where these color constants are defined?
Color XML file is within the values folder where it must contain color values.within resources tag.
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="green">#00ff00</color>
strangely Android does not provide a decent list of colors. And I say strangely because during my 30 years career this is the first language I met that does not do that. And that despite that is built on Java which defines colors in all it's basic libraries.
The ones that are defined are prefixed so you will not find them :) To find them (if using eclipse ) go to the xml doc where you need the color type android:background="@android:color/ and do a Ctrl Space. On my version (current as we speaking) I get more than a dozen. for instance: holo_orange_dark
So, use that or complain so Google fixes this issue. And I call it issue because it makes no sense to force all developers to manually describe all colors and values.
An important part of this that no one else has mentioned is that the reference to the color has to be
@color/black
but the xml file has to be
colors.xml
(note plural in the xml file name but not plural @color)
If you want to use the colors pre-defined in the Android platform, the syntax is @android:color/white. The "android:" at the beginning indicates that the resource is not part of your application.
Make sure your color XML file is within the values folder, not a colors folder.
So you should have...
values/colors.xml
<resources xmlns:android="http://schemas.android.com/apk/res/android">
<color name="red">#FF0000</color>
</resources>
and NOT this...
color/colors.xml
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<color name="red">#FF0000</color>
</selector>
Note that the tag is resources, not selector.