1. Android设置文本颜色的4种方法:
(1)利用系统自带的颜色类:
tv.setTextColor(android.graphics.Color.RED);
(2)数字颜色表示:
tv.setTextColor(0xffff00ff);
(3)自定义颜色:
1 <?xml version="1.0" encoding="utf-8"?> 2 <resources> <drawable name="dkgray">#80808FF0</drawable> <drawable name="yello">#F8F8FF00</drawable> 3 <drawable name="white">#FFFFFF</drawable> 4 <drawable name="darkgray">#938192</drawable> 5 <drawable name="lightgreen">#7cd12e</drawable> 6 <drawable name="black">#ff000000</drawable> 7 <drawable name="blue">#ff0000ff</drawable> 8 <drawable name="cyan">#ff00ffff</drawable> 9 <drawable name="gray">#ff888888</drawable> 10 <drawable name="green">#ff00ff00</drawable> 11 <drawable name="ltgray">#ffcccccc</drawable> 12 <drawable name="magenta">#ffff00ff</drawable> 13 <drawable name="red">#ffff0000</drawable> 14 <drawable name="transparent">#00000000</drawable> 15 <drawable name="yellow">#ffffff00</drawable> 16 </resources>
根据个人需要,颜色可以自行添加。
在Java中设置:
tx.setTextColor(tx.getResources().getColor(R.drawable.red));
color.xml中也可用color标签:
<color name="red">#ffff0000</color>
Java中设置相应改为:
tx.setTextColor(tx.getResources().getColor(R.color.red));
(4)直接在xml的TextView中设置:
android:textColor="#f8f8ff00"
或者
android:textColor="#f8ff00"