設置隨機字體顏色
安卓中的字號一般都是12 或者14以上
通過rgb設置隨機顏色值
//獲取隨機rgb顏色值
public static intrandomColor(){
Random random = new Random();
int red =random.nextInt(150);//0-190 ,如果顏色值過大,就越接近白色,就看不清了,所以需要限定范圍
int green =random.nextInt(150);//0-190
int blue =random.nextInt(150);//0-190
return Color.rgb**(red,green, blue);//使用rgb混合生成一種新的顏色,Color.rgb生成的是一個int數
}
//設置隨機顏色
textView.setTextColor(ColorUtil.randomColor());
setTextColor(int color)使用誤區
這里注意,setTextColor需要的是一個int類型的顏色值,而平時大家在使用時,往往容易直接將定義的color的resId傳進去,
這時候系統會將resId對應的int值作為顏色值,此時正確的使用方法應該是 context.getResource().getColor(resId)。