I am trying to set some common colors for the program I am writing. I created the colors.xml file and am trying to directly refer to the colors from the layout.xml file. I believe that I am doing it right, but it gives me the following error:
Color value '@colors/text_color' must start with
Here are my res / values ββ/colors.xml
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="background_color">#888888</color> <color name="text_color">#00FFFF</color> </resources>
Here is my res / layout / main.xml
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical"> <TextView android:layout_width="fill_parent" android:text="@string/hello" android:layout_height="wrap_content" android:id="@+id/TextView01" android:textColor="@colors/text_color"/> </LinearLayout>
I looked at some links on the Android developer site: Additional resource types: Color and found this code:
Example: XML file saved in res / values ββ/colors.xml:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name="opaque_red">#f00</color> <color name="translucent_red">#80ff0000</color> </resources>
This application code retrieves a color resource:
Resources res = getResources(); int color = res.getColor(R.color.opaque_red);
This XML layout applies color to the attribute:
<TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:textColor="@color/translucent_red" android:text="Hello"/>
I think that my two xml files follow this example quite closely - however, the only difference is that I did not use the application code to extract the color resource. I donβt think itβs necessary (but thatβs the difference.) I thought I would see if anyone else has any problems or solution? or is it a mistake?
I updated all my Android sdk (and Eclipse) files last week, so I think they were the last.
android
user657019 Mar 12 '11 at 23:23 2011-03-12 23:23
source share