colors.xml不产生在根/ R文件的正确的价值观? [英] colors.xml not generating the correct values in gen/R file?

查看:170
本文介绍了colors.xml不产生在根/ R文件的正确的价值观?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想访问的每个值在colors.xml,但在R /色类INT(十六进制)值不匹配相应的colors.xml中定义的值。下面是一些样本值:

  R /颜色(所有这一切都始于0x7f0400 ...):
    公共静态最终诠释艾莉斯蓝= 0x7f04002d;
    公共静态最终诠释古董白= 0x7f040023;
    公共静态最终诠释的Aqua = 0x7f04007d;
    公共静态最终诠释蓝宝石= 0x7f040062;
    公共静态最终诠释天青= 0x7f04002b;
... 但在colors.xml(所有这些始于#00 ...):
    <颜色名称=艾莉斯蓝>#F0F8FF< /彩色>
    <颜色名称=古董白>#FAEBD7< /彩色>
    <颜色名称=水族>#00FFFF< /彩色>
    <颜色名称=海蓝宝石>#7FFFD4< /彩色>
    <颜色名称=天青>#F0FFFF< /彩色>


解决方案

R.java 0x7f04002d )不设对应于十六进制code在 colors.xml (例如, F0F8FF )。在 R.java INT 号是系统在编译程序产生的标识符。

当您使用 R.color.AliceBlue 访问它,它会在 INT > R.java ,应该返回正确的颜色。

您甚至不应该需要/想在 R.java乱搞所以不用担心在那里,只要它返回正确的色彩是什么。另外请注意,你不能依赖于 INT ,因为他们可以从编译更改编译,所以你不想引用 INT 。你刚才提到你给它来指如古董白的名称。

要引用这一点,你需要获得一个颜色通过引用其 ID 使用的getColor ()

 新ForegroundColorSpan(getResources()的getColor(艾莉斯蓝)。);

I'm trying to access each of the values in colors.xml, but the int (hex) values in the R/color class doesn't match corresponding values that are defined in colors.xml. Here are some sample values:

 R/color (all of which starts with 0x7f0400...):
    public static final int AliceBlue=0x7f04002d;
    public static final int AntiqueWhite=0x7f040023;
    public static final int Aqua=0x7f04007d;
    public static final int Aquamarine=0x7f040062;
    public static final int Azure=0x7f04002b;
...

 But in colors.xml (all of which starts with #00...):
    <color name="AliceBlue">#F0F8FF</color>
    <color name="AntiqueWhite">#FAEBD7</color>
    <color name="Aqua">#00FFFF</color>
    <color name="Aquamarine">#7FFFD4</color>
    <color name="Azure">#F0FFFF</color>

解决方案

The number in your R.java (0x7f04002d) isn't suppose to correspond to your hex code in colors.xml (ex. F0F8FF). The int number in R.java is an identifier that the system generates when you compile your program.

When you access it with R.color.AliceBlue it will reference the int in R.java and should return the correct color.

You shouldn't even need/want to be messing around in R.java so don't worry about what's in there as long as it is returning the correct colors. Also note that you can't rely on that int because they can change from compile to compile so you don't want to reference that int. You just reference the name you gave it to refer to such as AntiqueWhite.

To reference this you need to get a Color by referencing its id using getColor()

new ForegroundColorSpan(getResources().getColor(AliceBlue));

这篇关于colors.xml不产生在根/ R文件的正确的价值观?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆