Android Studio can't find color reference within the same resource file

纵饮孤独 提交于 2019-12-08 04:51:00

问题


Here's the content of my resource file \res\values\colors.xml:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="themeGray">#ff8A9199</color>
    <color name="themeLightGray">#ffeaeaea</color>
    <color name="themeDarkGray">#ff3f434b</color>
    <color name="themeRed">#ffCC292B</color>
    <color name="themeBlue">#ff002E63</color>
    <color name="themeWhite">#ffffffff</color>
    <color name="buttonNormal">@color/themeGray</color>
    <color name="buttonPressed">@color/themeBlue</color>
</resources>

The two values

@color/themeGray
@color/themeBlue

are red colored Cannot resolve symbol '@color/themeGray'

EDIT

This what I see in the Message windows:

Error:Execution failed for task ':app:mergeDebugResources'.
> java.lang.NullPointerException (no error message)

回答1:


After trying with project clean/compile and File>Invalidate Caches / Restart... with no success, I solved the problem relocating the project to another folder.




回答2:


Change

xmlns="http://schemas.android.com/tools"

to

xmlns="http://schemas.android.com/apk/res-auto"

lets see what happens




回答3:


That also depends on where your are trying to access the resource files. some fields only take rgb format for colors.



来源:https://stackoverflow.com/questions/26422286/android-studio-cant-find-color-reference-within-the-same-resource-file

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