Android的.xml文件:为什么predefined颜色不适合我? [英] Android .xml files: Why do predefined colors not work for me?
问题描述
当我看着杂项。 Android的教程和例子,当涉及到指定的颜色我经常看到这样 @色/红色
或 @彩色/黑白
等被使用。对于一些奇怪的原因,从来没有对我的作品!我总是需要指定使用#RGB的色彩,#ARGB,...,#AARRGGBB符号。
When I look at misc. Android tutorials and examples when it comes to specifying colors I very often see constants like @color/red
or @color/black
etc. being used. For some strange reason that NEVER works for me! I always need to specify colors using the "#RGB", #ARGB, ..., #AARRGGBB notation.
一旦,我尝试使用任何例如像那些记忆常数@色/红色的我收到错误消息像这样的:
As soon, as I try to use any of those mnemonic constants like e.g. "@color/red" I am getting error messages like these:
[...] 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').
为什么会这样呢?为什么我不能使用这些predefined常数?我需要preFIX他们提供一些包名(我试过 @android:颜色/红
,但只造成了不同的错误)?
我是否需要指定这些颜色的自己?如果是这样的:如何以及在何处?任何意见或建议?
Why is that so? Why can't I use these predefined constants? Do I need to prefix them with some package name (I tried @android:color/red
but that only caused a different error)?
Do I need to specify these colors myself? If so: how and where? Any ideas or suggestions?
迈克尔
推荐答案
是colors.xml添加到您的RES /值,其中这些颜色常量定义的文件夹?
Is "colors.xml" added to your res/values folder where these color constants are defined?
这篇关于Android的.xml文件:为什么predefined颜色不适合我?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!