How to change font color of a textView
I want to use the below method of textView 开发者_开发技巧to change the font color. What format can I use to specify the color?
public void setTextColor (int color)
Sets the text color for all the states (normal, selected, focused) to be this color.
I've tried this:
text.setTextColor(#FF0000)
But it's not a valid syntax.
TextView.setTextColor(Color.BLUE);
TextView.setTextColor(Color.RED);
Or this :
textView.setTextColor(Color.rgb(255,0,0)); // rgb( red , green , blue ) ;
For set that color u have many options... 1 textview.setTextColor(Color.rgb(012,255,0));
2 first define the color in values... values.xml is define in your project under src folder... U can add your color as below
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string name="hello">Hello World</string>
<string name="app_name">XYZ</string>
<color name="SkyBlue">#56A5EC</color>
<color name="Green">#347C17</color>
</resources>
after define color in values simply use as below...
textview.setTextColor(R.Color.SkyBlue);
You should use the color class. Read about it here: http://developer.android.com/reference/android/graphics/Color.html
It expects a 32bit color value. You can create one using the Color class: http://developer.android.com/reference/android/graphics/Color.html#rgb(int, int, int)
edit: you can also use 0xAARRGGBB (in your case, that would be 0x00FF0000 for pure red).
I am totally agree with answers of Mohit Kanada and Houcine.
But let me add something here, you can also use some built-in resources provided by android itself, just refer below image:
精彩评论