【发布时间】:2011-04-27 05:04:56
【问题描述】:
当我看杂项。关于指定颜色的 Android 教程和示例 我经常看到使用了 @color/red 或 @color/black 等常量。出于某种奇怪的原因,这对我来说从来没有用过!我总是需要使用“#RGB”、#ARGB、...、#AARRGGBB 表示法来指定颜色。
当我尝试使用任何助记符常量时,例如"@color/red" 我收到如下错误消息:
[...] C:\Users\mmo\Test\res\drawable\edit_text.xml:5: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/orange').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:3: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:4: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:5: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/green').
[...] C:\Users\mmo\Test\res\drawable\myDrawable.xml:6: error: Error: No resource found that matches the given name (at 'drawable' with value '@color/black').
为什么会这样?为什么我不能使用这些预定义的常量?我是否需要在它们前面加上一些包名(我试过@android:color/red,但这只会导致不同的错误)?
我需要自己指定这些颜色吗?如果是这样:如何以及在哪里?有什么想法或建议吗?
迈克尔
【问题讨论】:
标签: android