gpt4 book ai didi

Android .xml 文件 : Why do predefined colors not work for me?

转载 作者:IT老高 更新时间:2023-10-28 21:53:31 26 4
gpt4 key购买 nike

当我看杂项。关于指定颜色的 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平台预定义的颜色,语法为@android:color/white。开头的 android: 表示该资源不属于您的应用程序。

关于Android .xml 文件 : Why do predefined colors not work for me?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3963978/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com