There are two ways to use a resource file, one is to refer to it in XML, and one to refer to it in code.
For example, we define the following two colors in XML, which are quoted in the XML file, very simply, using @color/drakblue.
< resources > < color name = "Weakyellow" > #ee9c16 </ color > < color name = "Darkblue" > #445f74 </ color > </ resources >
But what if you reference it in your code?
I have been for quite a long time did not reference the resource file in the code, today occasionally quoted, unexpectedly tried for a period of time, before the color tune normal.
At first I was defining this:
colors = new Integer[]{color.cyan,color.dkgray,color.blue,color.green,color.ltgray,color.magenta,color.black, Color.red,color.yellow,color.white,r.color.weakyellow,r.color.darkblue};
In front of which is the system comes with color, because the system itself provides 10 colors, to the 11th and 12 kinds of time, can only be defined by themselves, so there is the front I define the two colors, write the array, let its natural imitation of the previous form of a:
R.clor.darkblue
Looks like the form is also pretty well, when the test found that no matter how, the latter two colors show a solid color, completely unrelated to my definition.
How can we define that? Completely forget the basic concept, what does "r.clor.darkblue" mean? The students?
It represents the resource value, and the contents of each resources will generate a unique ID value in the R file, which has nothing to do with color!
As an example, use
Textview.settext (r.string.me)
Is that right? Inside is the int value, where is the string yo you want!
Well, the right way should be familiar with this kind of drip ... Goodbye ~
colors = new Integer[]{color.cyan,color.dkgray,color.blue,color.green,color.ltgray,color.magenta,color.black, Color.red,color.yellow,color.white,getresources (). GetColor (R.color.weakyellow), Getresources (). GetColor ( R.color.darkblue)};
Getresources (). GetColor (R.color.darkblue)
How Android uses the color defined by the resource file