1.int的理解
第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,当然前提是需要
在相应的配置文件里做相应的配置,如:
#FF0000
#FF0000
#FF0000
2.动态颜色
产生随机颜色的方法 :
//随机颜色
public int changecolor()
{
Random random=new Random();
int a=random.nextInt(256);
int r=random.nextInt(256);
int g=random.nextInt(256);
int b=random.nextInt(256);
int color = Color.argb(a,r,g,b);
return color;