4 numbers are used in Android to represent colors, namely alpha, red (red), green (green), Blue (blue), and four color values (ARGB). Each number is valued at 0-255, so a color can be represented by an integer. To run efficiently, the Android encoding uses an integer color class instance to represent colors.
The three values of red, green, and blue are the values that represent the color, and alpha represents transparency. The lowest value is 0, which indicates that the color is completely transparent, and what the RGB value is not important at this time. The highest possible alpha value is 255, which indicates that the color is completely opaque. If you need color transparency and translucency, you can take some values in the middle of the value 0-255, which is often used when the front-end layer is drawn.
There are several ways to create or represent a color:
1. Use the constants of the color class, such as:
Int color = color.bule; // Create a blue
2. If you know the value of ARGB, you can create a color using the static method of the color class ARGB:
Int color = Color.argb (127,255,0,255);// Translucent Purple
3. Use an XML resource file to represent the color. This is a more scalable way to make it easy to modify color values in the future.
<?xml version= "1.0" encoding= "utf-8" ><resources> <color name= "MyColor" ># 7fff00ff</color></resources>
Defines a color named MyColor, where you can refer to MyColor to get the color value elsewhere. You can use GetColor in the ResourceManager class to get the color. The Java sample code is as follows:
Int color = getresources (). GetColor (R.color.mycolor);
This is the same as the value obtained from the second method. The Getresources () method returns the ResourceManager class instance of the currently active activity.
Android colors Color