2013-07-18 34 views
1

我試圖使用色彩資源時發生lint錯誤。根據文件,以下內容應該是有效的。色彩資源中的錯誤

<?xml version="1.0" encoding="utf-8"?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <color name="actionbar_title"></color> 
</resources> 

但是這給出了「屬性缺少Android命名空間前綴」。修訂到

<?xml version="1.0" encoding="utf-8"?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <color android:name="actionbar_title"></color> 
</resources> 

清除錯誤,但在佈局文件中的以下定義

<TextView android:id="@+id/title" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:layout_width="0dp" 
      android:textAppearance="?android:attr/textAppearanceMedium" 
      android:textColor="@color/actionbar_title" /> 

給出了錯誤「錯誤:錯誤:沒有資源發現在給定的名稱與價值相匹配(在‘文字顏色’ 「@顏色/ actionbar_title」)

任何和所有幫助將受到讚賞

編輯:。 如由類型a1pha指出,上面沒指定一種顏色 - 我從測試版本複製。然而

<?xml version="1.0" encoding="utf-8"?> 
<resources xmlns:android="http://schemas.android.com/apk/res/android"> 
    <color android:name="actionbar_title">#ffffff</color> 
</resources> 

給lint警告

Unexpected text found in layout file: "#ffffff" 

但顏色資源仍然沒有在佈局xml文件的認可。

+0

那麼用名稱替換android:name呢? – kvh

回答

2

實際上你需要定義顏色:

<color name="white">#FFFFFF</color> 

就是給它的十六進制代碼。

0
<color name="actionbar_title"></color> 

我看到的顏色是空的。

<color name="actionbar_title">#000000</color> 
0

您應該將文件放在「值」文件夾下而不是「彩色」文件夾下。