欢迎来到 Android人的问与答 ,在这里提问或帮助他人解答。 Question2Answer的1.6.x和1.7.x版本的中文翻译包我修改更新:

Question2answer

如何使用中文语言包

Q2A 1.6.x - Chinese Simplified (简体中文)

Q2A 1.7.x - Chinese Simplified (简体中文)


国内服务器推荐 阿里云服务器
国外服务器推荐 DigitalOcean
VPN推荐 正版Green VPN
阿里云推荐码:ldvq50

Android中如何在代码中设置TextView的字体颜色

1 喜欢 0 不喜欢
162 浏览

You should use:

holder.text.setTextColor(Color.RED);
For a sanity check, I just tried it, because I had a project open anyway, and yes, it's nice and red ;D

You can use various functions from the Color class to get the same effect of course.

Color.parseColor (Manual) (like LEX uses)

text.setTextColor(Color.parseColor("#FFFFFF"));
Color.rgb and Color.argb (Manual rgb) (Manual argb) (like Ganapathy uses)

holder.text.setTextColor(Color.rgb(200,0,0));
holder.text.setTextColor(Color.argb(0,200,0,0));
And of course, if you want to define your color in an XML file, you can do this:

<color name="errorColor">#f00</color>
and then use this code to show it:

textView.setTextColor(getResources().getColor(R.color.errorColor));
You can also insert plain HEX, like so:

myTextView.setTextColor(0xAARRGGBB);
Where you have an alpha-channel first, then the color value.

Check out the complete manual of course, public class Color extends Object.

 
最新提问 12月 31, 2014 分类:Android View | 用户: forlong401 (7,050 分)

登录 或者 注册 后回答这个问题。

...