Androidcolor (color) is in the XML file and java code. if you need it, refer to it. Android color is in the XML file and java code. For more information, see.
1. use constants of the Color class, such:
Int color = Color. BLUE; // create a BLUE color that is provided by Android. int Color = color. RED; int Color = color. WHITE;
2. build with ARGB, such:
Int color = Color. argb (127,255, 0,255); // translucent purple. The first parameter indicates transparent, 0 indicates completely transparent, and 255 (ff) indicates completely opaque; the last three digits represent the RGB values.
3. use an XML Resource file to define the color
This method is highly scalable and easy to modify and share. for example, you can create a color. xml file in the values Directory:
#7fff00ff
Defines a color named mycolor. in other places, you can reference mycolor to obtain the color value, as shown in
TextView definition:
Android:textColor="@drawable/mycolor"
In Java code, you can use the getColor in the ResourceManager class to obtain the color:
int color = getResources().getColor(R.color.mycolor);
This is the same as the value obtained in the second method. the getResources () method returns the ResourceManager class instance of the current Activity.
Note: The XML definition method can be 6-bit or 8-bit, and must start with #. The first two digits of the 8-bit definition indicate transparency. (For simplicity, it can also be abbreviated), for example:
#f00
#0000ff
#f0f0
#ffffff00
4. define the color value directly, for example:
int color = 0xff00ff00;
This method must start with 0x instead #. Unlike method 3, the value must also be 8 bits, and 6 bits are not allowed. Group 0x | ff | ff00ff. 0x indicates the color integer, ff indicates the transparency, and ff00ff indicates the RGB color value.
The above is a detailed description of the code of Android color in the XML file and java code. For more information, see other related articles in the first PHP community!