2014-07-13 45 views
1

我有這個「colors.xml」文件:錯誤使用是指顏色的字符串設定文字顏色

<?xml version="1.0" encoding="utf-8"?> 
<resources> 

<!-- Absolute colors --> 
<color name="red">#FF0000</color> 

<!-- Application colors --> 
<string name="error_message_color">@color/red</string> 

</resources> 

我使用的應用程序的顏色設置一個TextView的文本顏色以這樣的方式

<TextView 
    android:id="@+id/error_message_textView" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="@string/error_message_label" 
    android:textAppearance="?android:attr/textAppearanceMedium" 
    android:textColor="@string/error_message_color" 
    android:visibility="invisible"/> 

但現在,使用Eclipse ADT 23.0.2.1259578部分

<string name="error_message_color">@color/red</string> 

給這個錯誤:的Une xpected資源引用類型;期望值@字符串/

而且我不能編譯。

這是爲什麼?有人知道我該如何解決?

PS:我知道,如果我將使用@色/紅色文字顏色屬性的問題將得到解決,但我會保留「應用顏色」的編碼風格...

感謝

+0

你是否認真**?你假裝把一個** ** **應該在哪裏?你爲什麼要混合**顏色和字符串? –

+1

只需直接使用'@ color/red',不需要使用字符串資源。 – kabuto178

+1

請將android:textColor =「@ string/error_message_color」替換爲android:textColor =「@ color/red」或直接輸入十六進制顏色代碼android:textColor =「#FF0000」 –

回答

1

如果你真的想爲你的顏色設置別名,請嘗試引用顏色中的顏色,然後使用它。

<!-- Absolute colors --> 
<color name="red">#FF0000</color> 

<!-- Application colors --> 
<color name="error_message_color">@color/red</color> 

... 

android:textColor="@color/error_message_color" 
+0

也許我解釋了這個問題不好(對不起我的英語)。在我的xml文件中使用的編碼風格發現在一本關於Android的書中,它的工作很好,直到ADT的版本。我知道建議避免編譯錯誤的方式,但是我會知道是否會出現此問題,因爲它直接使用顏色更好,並且可能不贊成使用該示例中顯示的方式,或者它是ADT問題。 – Luca122131