1. Definition of color values in Android:
The color value is defined by RGB primary colors and an Alpha value. The color value is defined as a # At the beginning, followed by the Alpha-red-green-blue format. For example, # RGB # argb # rrggbb # aarrggbb.
2.Definition of the Color Resource XML file
I. resource location: the Res/values/colors. xml file name is not limited to any conforming name of color.
Ii. Color XML file format 1.
<? XML version = "1.0" encoding = "UTF-8"?> <Resources> root element <color> child element: <color name = color_name> # color_value </color> </resources>
For example:
<?xml version="1.0" encoding="utf-8"?> <resources> <color name=white>#ffffff</color> </resources>
2.
<?xml version="1.0" encoding="utf-8"?> <resources> <drawable name="white">#ffffffff</drawable></resources>
2. Reference of color in XML: 1
android:textColor="@color/white"
2android:textColor="@drawable/white"
And so on, I believe you know what to do in strings. xml and how to do it in style ..
3. color reference in Java code
tv = (TextView)this.findViewById(R.id.tv01); 1 tv.setTextColor(Color.RED); 2 tv.setTextColor(0xff000000); 3 Resources rs = this.getResources(); tv.setTextColor(rs.getColor(R.drawable.red)); 4 tv.setTextColor(Color.rgb(red, green,blue));
1st types: TV. settextcolor (Android. Graphics. color. Red); // color class that comes with the System
2nd types: TV. settextcolor (0xffff00ff); // 0xffffff00ff is int type data, grouped by 0x | FF | ff00ff, 0x indicates the color integer, FF indicates the transparency, and ff00ff indicates the color, note: Here, ffff00ff must be represented by 8 colors, and 6 colors such as ff00ff are not accepted.
3rd types: TV. settextcolor (this. getresources (). getcolor (R. color. Red); // you can set it by obtaining the resource file. Depending on the situation, R. color. Red can also be R. String. Red or R. drawable. Red. Of course, the premise is that you need to configure it in the corresponding configuration file.
By setting the text color in the code, we can achieve the dynamic text color.