Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
269 views
in Technique[技术] by (71.8m points)

android - colors.xml not generating the correct values in gen/R file?

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>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The values in the R file are not the values that you define they are the id that will be assigned to each color so you access them. You can use R.color.AliceBlue and it will give you the value you assigned to it in colors.xml. Do Not modify the R.java file. It is generated automatically.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...