android在代码中设置TextView的颜色
2015-04-16 14:27
323 查看
在代码中设置TextView,有两个重载方法,一个是传ColorStateList 类型,一个是穿int类型
传ColorStateList类型的,一般是用于那些XML自定义的颜色,比如selector等等。
Resources resource = (Resources) getBaseContext().getResources();
ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.my_color);
if (csl != null) {
tv.setTextColor(csl);
}
而int类型,是传颜色的rgb值,也就是16进制,不是资源的ID,这点要记住
tv.setTextColor(Color.rgb(255, 255, 255));
传ColorStateList类型的,一般是用于那些XML自定义的颜色,比如selector等等。
Resources resource = (Resources) getBaseContext().getResources();
ColorStateList csl = (ColorStateList) resource.getColorStateList(R.color.my_color);
if (csl != null) {
tv.setTextColor(csl);
}
而int类型,是传颜色的rgb值,也就是16进制,不是资源的ID,这点要记住
tv.setTextColor(Color.rgb(255, 255, 255));
相关文章推荐
- android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法
- android Java代码设置textview的字体资源颜色
- android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法
- Android:TextView代码动态设置colors.xml颜色
- android使用java代码设置textview、button等内容颜色
- android在代码中四种设置控件(以及TextView的文字颜色)背景颜色的方法
- Android在代码中设置textview字体颜色
- Android 代码里动态设置TextView/Button等的文字颜色Seletor
- 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色
- [置顶] android,在java代码中,如何给textview设置不同的颜色,以及引用color中资源设置颜色
- android,在java代码中,如何给textview设置不同的颜色,以及引用color中资源设置颜色
- Android 在代码中为textview设置自定义的颜色
- Android 代码中设置TextView字体颜色
- Android用代码给TextView中间部分设置不同的颜色
- Android 代码设置TextView 字体颜色--ColorStateList
- Android 代码中设置控件背景颜色,以TextView为例
- android textview可以设置文字颜色 部分文字点击事件处理
- android中用Spannable在TextView中设置超链接、颜色、字体
- android之TextView部分本文变颜色,并设置文本监听器
- android 一个 textview 设置不同的字体大小和颜色