Errors in color resources

谁说我不能喝 提交于 2021-01-28 10:39:10

问题


I'm getting lint errors attempting to use color resources. According to the documentation, the following should be valid.

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

But this gives "Attribute is missing the Android namespace prefix". Amending to

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

clears the error but in a layout file the following definition

<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" />

gives the error "error: Error: No resource found that matches the given name (at 'textColor' with value '@color/actionbar_title').

Any and all help will be appreciated.

EDIT: As pointed out by type-a1pha, the above did not specify a color - I've copied from a test version. However

<?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>

gives the lint warning

Unexpected text found in layout file: "#ffffff"

but the color resource is still not recognised in the layout xml file.


回答1:


You need to actually define the color:

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

that is, give its hexadecimal code.




回答2:


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

the color is empty i see.

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



回答3:


You should put your file under "values" folder instead of the "color" folder.



来源:https://stackoverflow.com/questions/17735564/errors-in-color-resources

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!