我想使用textView的以下方法更改字体颜色。 我可以使用什么格式来指定颜色?如何更改textView的字体颜色
public void setTextColor (int color)
设置所有状态的文本颜色(正常,选择的重点)是这个颜色。
我已经试过这样: text.setTextColor(#FF0000)
但它不是一个有效的语法。
我想使用textView的以下方法更改字体颜色。 我可以使用什么格式来指定颜色?如何更改textView的字体颜色
public void setTextColor (int color)
设置所有状态的文本颜色(正常,选择的重点)是这个颜色。
我已经试过这样: text.setTextColor(#FF0000)
但它不是一个有效的语法。
TextView.setTextColor(Color.BLUE);
TextView.setTextColor(Color.RED);
或者这样:
textView.setTextColor(Color.rgb(255,0,0)); // rgb(red , green , blue) ;
它需要一个32位颜色值。您可以使用颜色类创建一个:http://developer.android.com/reference/android/graphics/Color.html#rgb(int,int,int)
编辑:您也可以使用0xAARRGGBB(在您的情况下,这将是纯红色0x00FF0000)。
对于一套颜色U有很多选择...... 1 textview.setTextColor(Color.rgb(012,255,0));
2第一定义值的色彩...... values.xml是在你的项目中定义src文件夹下... U可以添加你的颜色,如下
<?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>
在值之后定义颜色简单使用如下...
textview.setTextColor(R.Color.SkyBlue);
我完全同意Mohit Kanada和Houcine的答案。
但是让我在这里补充一下,你也可以透过Android本身提供了一些内置的资源,只是参考下图: