Tv.settextcolor (Color.parsecolor ("#FFFFFF"));
TV. SetTextColor (color.white);
Tv.settextcolor (Color.rgb (255, 255, 255));
Note that color is uppercase C, not Color.holo_orange_dark, so the error is not effective
Tv.setbackgroundresource (R.drawable.icon_bg_rectang_stroke);
This method is to pass in the int color value, which is not an int value that is automatically assigned in the R file, so be careful. This is the color int value constructed by the static method in the Color class.
-------------------------------------------------------------------------------------
Another method: Tv.settextcolor (This.getresources (). GetColor (r.color.red));
Set up by obtaining a resource file. Depending on the situation r.color.red can also be r.string.red or r.drawable.red,
Of course, the premise is to do the corresponding configuration files in the corresponding configuration, such as:
#FF0000
< drawable name= "Red" > #FF0000
< string name= "Red" > #FF0000
Note the third method above, you must not define your own color directly as a parameter, for example:
Tv.settextcolor (r.color.red); This situation will cause color errors!
--------------------------------------------------------------------
Another way:
1 Resources resource = (resources) Getbasecontext (). Getresources (); 2 colorstatelist CSL = (colorstatelist) resource.getcolorstatelist (r.color.my_color); 3 if NULL ) {4 Tv.settextcolor (CSL); 5 }
This method is obtained by colorstatelist the configured colors in the XML. A lot of the XML files that need to be configured like this are mapped.
There is another way:
1 xmlresourceparser XRP = getresources (). GETXML (R.color.my_color); 2 Try {3 Colorstatelist CSL = colorstatelist.createfromxml (getresources (), XRP); 4 Tv.settextcolor (CSL); 5 Catch (Exception e) {6 }
There are methods to set the color of TextView in Android SetTextColor, this method is overloaded and can pass in two kinds of parameters.
1 Public voidSetTextColor (intcolor) {2Mtextcolor =colorstatelist.valueof (color);3 updatetextcolors ();4 }5 6 Public voidSetTextColor (colorstatelist colors) {7 if(Colors = =NULL) {8 Throw Newnullpointerexception ();9 }Ten OneMtextcolor =colors; A updatetextcolors (); -}
View color values: (From: http://blog.csdn.net/lincyang/article/details/5871117)
<?xml version= "1.0" encoding= "Utf-8"?><resources> <drawable name= "Dkgray" > #80808FF0 </ drawable> <drawable name= "Yello" > #F8F8FF00 </drawable> <drawable name= "White" > #FFFFFF </ drawable> <drawable name= "Darkgray" > #938192 </drawable> <drawable name= "LightGreen" > #7cd12e </drawable> <drawable name= "Black" > #ff000000 </drawable> <drawable name= "Blue" > #ff0000ff </drawable> <drawable name= "Cyan" > #ff00ffff </drawable> <drawable name= "Gray" > #ff888888 < /drawable> <drawable name= "green" > #ff00ff00 </drawable> <drawable name= "Ltgray" > #ffcccccc </ drawable> <drawable name= "Magenta" > #ffff00ff </drawable> <drawable name= "Red" > #ffff0000 </ drawable> <drawable name= "Transparent" > #00000000 </drawable> <drawable name= "Yellow" > #ffffff00 </drawable></resources>
<?xml version= "1.0" encoding= "Utf-8"?> <resources> <color name= "White" > #FFFFFF </color><! --white---<color name= "Ivory" > #FFFFF0 </color><!--Ivory--<color name= "Lightyellow" > #FFFFE0 </color><!--Bright yellow-<color name= "Yellow" > #FFFF00 </color><!--Yellow-to-<color name= " Snow > #FFFAFA </color><!--Snow White--<color name= "Floralwhite" > #FFFAF0 </color><!--Flowers White-- > <color name= "LemonChiffon" > #FFFACD </color><!--Lemon silk-and <color name= "Cornsilk" > #FFF8DC </color><!--M-<color name= "Seashell" > #FFF5EE </color><!--Sea-and <color name= " Lavenderblush > #FFF0F5 </color><!--Mauve-to <color name= "papayawhip" > #FFEFD5 </color>< !--Parquet--<color name= "Blanchedalmond" > #FFEBCD </color><!--White Apricot--<color name= "Mistyrose" > #FFE4E1 </color><!--Light Rose-to <color name= "bisque" > #FFE4C4 </color><!--Orange-to <color name= "Moccasin" > #FFE4B5 </color><!--deerskin-and <color name= " Navajowhite "> #FFDEAD </color><!--Nawa--<color name=" Peachpuff "> #FFDAB9 </color><!-- Peachy-<color name= "Gold" > #FFD700 </color><!--Gold-and <color name= "Pink" > #FFC0CB </color ><!--Pink--<color name= "Lightpink" > #FFB6C1 </color><!--Bright pink---<color name= "Orange" > #FFA500 </color><!--Orange-to <color name= "Lightsalmon" > #FFA07A </color><!--Bright Beige-- <color name= "Darkorange" > #FF8C00 </color><!--Dark orange-to-<color name= "Coral" > #FF7F50 </color ><!--Coral-<color name= "Hotpink" > #FF69B4 </color><!--Hot Pink--<color name= "tomato" > #FF6347 </color><!--Tomato-to-<color name= "orangered" > #FF4500 </color><!--Red-orange-- <color name= "Deeppink" > #FF1493 </color><!--Dark pink-to <color name= "fuchsia" >, #FF00FF </color><!--fuchsia-<color name= "Magenta" > #FF00FF </color><!--Red-purple-to-< Color name= "Red" > #FF0000 </color><!--Red---<color name= "Oldlace" > #FDF5E6 </color><!-- Old Colors--<color name= "Lightgoldenrodyellow" > #FAFAD2 </color><!--Bright golden Yellow--<color name= "linen" > #FAF0E6 </color><!--flaxen-<color name= "Antiquewhite" > #FAEBD7 </color><!--Antique White-and <color name= "Salmon" > #FA8072 </color><!--meat Color--<color name= "Ghostwhite" > #F8F8FF </color ><!--Ghosts----<color name= "Mintcream" > #F5FFFA </color><!--mint-to <color name= " WhiteSmoke "> #F5F5F5 </color><!--Smoke White--<color name=" Beige "> #F5F5DC </color><!--Beige-- > <color name= "Wheat" > #F5DEB3 </color><!--light Yellow-to <color name= "Sandybrown" > #F4A460 </ color><!--Sand-to-<color name= "Azure" > #F0FFFF </color><!--sky-Blue and <cOlor name= "Honeydew" > #F0FFF0 </color><!--Honey-to <color name= "AliceBlue" > #F0F8FF </color> <!--Allisland--<color name= "Khaki" > #F0E68C </color><!--Tan-to-<color name= "Lightcoral" ># f08080</color><!--Bright Coral--<color name= "Palegoldenrod" > #EEE8AA </color><!--Pale Unicorn-- <color name= "Violet" > #EE82EE </color><!--Violet-to <color name= "DarkSalmon" > #E9967A </ color><!--Dark Beige-to <color name= "Lavender" > #E6E6FA </color><!--Lavender--<color name= " Lightcyan "> #E0FFFF </color><!--Bright Cyan--<color name=" Burlywood "> #DEB887 </color><!-- Solid Wood--<color name= "Plum" > #DDA0DD </color><!--plum Color-<color name= "Gainsboro" > #DCDCDC < /color><!--Light Grey--<color name= "Crimson" > #DC143C </color><!--Dark Crimson---<color name= " palevioletred > #DB7093 </color><!--Violet-to <color name= "Goldenrod" > #DAA520 ≪/color><!--Gold Kylin--<color name= "Orchid" > #DA70D6 </color><!--Lavender--<color name= " Thistle "> #D8BFD8 </color><!--Thistle-<color name=" Lightgray "> #D3D3D3 </color><!--Bright Grey-- > <color name= "Lightgrey" > #D3D3D3 </color><!--Bright Gray-to <color name= "tan" > #D2B48C </color ><!--Tan-to-<color name= "Chocolate" > #D2691E </color><!--Power-to-<color name= "Peru" > #CD853F </color><!--Peru--<color name= "indianred" > #CD5C5C </color><!--Indian red-and < Color name= "mediumvioletred" > #C71585 </color><!--Violet--<color name= "Silver" > #C0C0C0 </ color><!--Silver--<color name= "Darkkhaki" > #BDB76B </color><!--dark brown-and <color name= " Rosybrown "> #BC8F8F </color><!--Brown rose-to-<color name=" Mediumorchid "> #BA55D3 </color><! --Medium pink--<color name= "Darkgoldenrod" > #B8860B </color><!--Dark Golden---<Color name= "Firebrick" > #B22222 </color><!--brick Color-<color name= "Powderblue" > #B0E0E6 </color ><!--Powder Blue--<color name= "Lightsteelblue" > #B0C4DE </color><!--Bright Steel Blue-to <color name= " Paleturquoise > #AFEEEE </color><!--Sapphire Green-to-<color name= "Greenyellow" > #ADFF2F </color> <!--Yellow-green-<color name= "LightBlue" > #ADD8E6 </color><!--Bright blue-and <color name= "Darkgray" > #A9A9A9 </color><!--Dark Grey--<color name= "Darkgrey" > #A9A9A9 </color><!--Dark Grey---< Color Name= "Brown" > #A52A2A </color><!--Brown--<color name= "Sienna" > #A0522D </color><!- -Ochre-<color name= "DarkOrchid" > #9932CC </color><!--dark purple-to <color name= "Palegreen" ># 98fb98</color><!--Pale green-to <color name= "Darkviolet" > #9400D3 </color><!--Dark Violet-to < Color name= "Mediumpurple" > #9370DB </color><!--Violet--<color name= "LightGreen" >, #90EE90 </color><!--Bright green--<color name= "Darkseagreen" > #8FBC8F </color><!--Dark Highland-- <color name= "SaddleBrown" > #8B4513 </color><!--Heavy Brown-and <color name= "Darkmagenta" > #8B008B < /color><!--Dark Magenta-to <color name= "darkred" > #8B0000 </color><!--dark red--<color name= " Blueviolet "> #8A2BE2 </color><!--Violet Blue-to <color name=" Lightskyblue "> #87CEFA </color> <!--bright sky-blue--<color name= "Skyblue" > #87CEEB </color><!--sky-and <color name= "Gray" ># 808080</color><!--Grey--<color name= "Grey" > #808080 </color><!--Grey--<color name= " Olive > #808000 </color><!--Olive--<color name= "Purple" > #800080 </color><!--Purple-to- <color name= "maroon" > #800000 </color><!--to <color name= "Aquamarine" > #7FFFD4 </color ><!--Green-to <color name= "Chartreuse" > #7FFF00 </color><!--Yellow-green--< color name= "Lawngreen" > #7CFC00 </color><!--Green---<color name= "Mediumslateblue" > #7B68EE </ color><!--Dark blue--<color name= "Lightslategray" > #778899 </color><!--Bright Blue Grey--and <color name = "Lightslategrey" > #778899 </color><!--Bright Blue Grey-to <color name= "Slategray" > #708090 </color> <!--Gray-to-<color name= "Slategrey" > #708090 </color><!--Gray-to-<color name= "Olivedrab" > #6B8E23 </color><!--dark brown-to <color name= "Slateblue" > #6A5ACD </color><!--Stone Blue--- <color name= "Dimgray" > #696969 </color><!--Dark Grey---<color name= "Dimgrey" > #696969 </color ><!--Dark Grey--<color name= "Mediumaquamarine" > #66CDAA </color><!--Green--<color name= " Cornflowerblue > #6495ED </color><!-----<color name= "Cadetblue" > #5F9EA0 </color>< !--Army Blue-<color name= "Darkolivegreen" > #556B2F </color><!--Dark olive green-and <cOlor name= "Indigo" > #4B0082 </color><!--Indigo-to-<color name= "mediumturquoise" > #48D1CC </color ><!--Emerald-to <color name= "Darkslateblue" > #483D8B </color><!--Dark gray blue-to <color name= " Steelblue "> #4682B4 </color><!--Steel Blue-<color name=" Royalblue "> #4169E1 </color><!-- Royal blue---<color name= "Turquoise" > #40E0D0 </color><!--Turquoise--<color name= "Mediumseagreen" ># 3cb371</color><!--Blue-to <color name= "Limegreen" > #32CD32 </color><!--Orange Green--< Color name= "Darkslategray" > #2F4F4F </color><!--Dark Tile Grey---<color name= "Darkslategrey" > #2F4F4F </color><!--Dark Tile Grey--<color name= "Seagreen" > #2E8B57 </color><!--Sea green and <color name= "Forestgreen" > #228B22 </color><!--Forest Green-to-<color name= "Lightseagreen" > #20B2AA </color> <!--bright Sea blue--<color name= "DodgerBlue" > #1E90FF </color><!--flashing blue-to <coloR name= "Midnightblue" > #191970 </color><!--Gray-to-<color name= "Aqua" > #00FFFF </color> <!--light green--<color name= "cyan" > #00FFFF </color><!--Cyan--and <color name= "Springgreen" ># 00ff7f</color><!--Spring Green--<color name= "lime" > #00FF00 </color><!--acid Orange--<color name = "Mediumspringgreen" > #00FA9A </color><!--Spring Green--<color name= "darkturquoise" > #00CED1 </ color><!--Dark Gem green--<color name= "Deepskyblue" > #00BFFF </color><!--deep sky blue-to <color name= " Darkcyan "> #008B8B </color><!--Dark Cyan--<color name=" teal "> #008080 </color><!--Teal-- > <color name= "green" > #008000 </color><!--Green to <color name= "Darkgreen" > #006400 </ color><!--Dark green--<color name= "Blue" > #0000FF </color><!--Blue--<color name= "MediumBlue > #0000CD </color><!--Blue-to <color name= "Darkblue" > #00008B </color><! --dark blue--<color name= "Navy" > #000080 </color><!--Navy--<color name= "BLACK" > #000000 </ color><!--Black-</resources>
Set the color of TextView in Android SetTextColor