Android中设置文本颜色的三种方法

1、利用系统自带的颜色类,如:

TextView1.setTextColor(android.graphics.Color.RED);

2、数字颜色表示法

TextView1.setTextColor(0xffff00ff);

3、自定义颜色

TextView1.setTextColor(this.getResources().getColor(R.drawable.red));

我在values文件夹下新建一个color.xml,内容如下:

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
<? xml  version = "1.0"  encoding = "utf-8" ?>
< resources >
     < drawable  name = "dkgray" >#80808FF0</ drawable >
     < drawable  name = "yello" >#F8F8FF00</ drawable >
     < drawable  name = "white" >#FFFFFF</ drawable >
     < drawable  name = "darkgray" >#938192</ drawable >
     < drawable  name = "lightgreen" >#7cd12e</ drawable >
     < drawable  name = "black" >#ff000000</ drawable >
     < drawable  name = "blue" >#ff0000ff</ drawable >
     < drawable  name = "cyan" >#ff00ffff</ drawable >
     < drawable  name = "gray" >#ff888888</ drawable >
     < drawable  name = "green" >#ff00ff00</ drawable >
     < drawable  name = "ltgray" >#ffcccccc</ drawable >
     < drawable  name = "magenta" >#ffff00ff</ drawable >
     < drawable  name = "red" >#ffff0000</ drawable >
     < drawable  name = "transparent" >#00000000</ drawable >
     < drawable  name = "yellow" >#ffffff00</ drawable >
</ resources >

你可能感兴趣的:(Android中设置文本颜色的三种方法)