问题
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