Skip to content Skip to sidebar Skip to footer

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 som

Solution 1:

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.

Solution 2:

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));

Post a Comment for "Colors.xml Not Generating The Correct Values In Gen/r File?"