android开发之形似“TextView.setTextColor(int)”括号里那个设置颜色的颜色int值的理解
2014-08-15 10:55
786 查看
第1种:
tv.setTextColor(android.graphics.Color.RED);//系统自带的颜色类
第2种:
tv.setTextColor(0xffff00ff);
//0xffff00ff是int类型的数据,分组一下 0x|ff|ff00ff,0x是代表颜色整数的标记,ff是表示透明度,ff00ff表示颜色。
//注意:这里ffff00ff必须是8个的颜色表示,不接受ff00ff这种6个的颜色表示。
第3种:
tv.setTextColor(this.getResources().getColor(R.color.red));//通过获得资源文件进行设置。根据不同的情况R.color.red也可以是R.string.red或者R.drawable.red,当然前提是需要在相应的配置文件里做相应的配置,如:
<color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>
注意上面的第三种方法,千万不能把自己定义的颜色直接当成参数,例如:
tv.setTextColor(R.color.red);这种情况会出现颜色错误!
转自:http://www.2cto.com/kf/201404/292488.html
tv.setTextColor(android.graphics.Color.RED);//系统自带的颜色类
第2种:
tv.setTextColor(0xffff00ff);
//0xffff00ff是int类型的数据,分组一下 0x|ff|ff00ff,0x是代表颜色整数的标记,ff是表示透明度,ff00ff表示颜色。
//注意:这里ffff00ff必须是8个的颜色表示,不接受ff00ff这种6个的颜色表示。
第3种:
tv.setTextColor(this.getResources().getColor(R.color.red));//通过获得资源文件进行设置。根据不同的情况R.color.red也可以是R.string.red或者R.drawable.red,当然前提是需要在相应的配置文件里做相应的配置,如:
<color name="red">#FF0000</color>
<drawable name="red">#FF0000</drawable>
<string name="red">#FF0000</string>
注意上面的第三种方法,千万不能把自己定义的颜色直接当成参数,例如:
tv.setTextColor(R.color.red);这种情况会出现颜色错误!
转自:http://www.2cto.com/kf/201404/292488.html
相关文章推荐
- TextView.setTextColor(int); 括号里那个颜色int值的理解
- TextView.setTextColor(int); 括号里那个颜色int值的理解
- 关于TextView.setTextColor(int); 括号里那个颜色int值的问题
- 关于TextView.setTextColor(int); 括号里那个颜色int值的问题
- Android中设置TextView的颜色setTextColor失败,变成灰色
- Android中设置TextView的颜色setTextColor
- 【转】Android中设置TextView的颜色setTextColor--代码中设置字体颜色
- Android编程设置TextView颜色setTextColor用法实例
- Android中设置TextView的颜色setTextColor
- Android中设置TextView的颜色setTextColor
- Android中设置TextView的颜色setTextColor
- Android中设置TextView的颜色setTextColor
- 【转】Android中设置TextView的颜色setTextColor
- Android中TextView中的文字颜色设置setTextColor的用法
- Android中设置TextView的颜色setTextColor
- Xamarin.Android 开发SetTextColor颜色设置
- Android中设置TextView的颜色setTextColor
- Android中设置TextView的颜色setTextColor
- android设置toolbar的menu itemTextView颜色 set toolbar menu item text color
- Android设置TextView颜色setTextColor