1. 程式人生 > >獲取Color的幾種方式

獲取Color的幾種方式

com 數值 hat == 字符 toc 格式 get test

#11223344 格式,11位表示透明度,為0時完全透明,為255時完全不透明,後三個分量依次表示R,G,B顏色參數。

//獲取顏色字符串  得到 #ffffff格式字符串 
// colorTest 為 #FF0000

String c0=this.getResources().getString((int)R.color.colorTest);

//獲取顏色數值,為8位數表示

int c1 = this.getResources().getColor(R.color.colorTest);

int c2 = Color.parseColor("#FF0000");

int c3 = 0xFF0000;

int c4 = 0xFFFF0000;

int c5= Color.argb(255,255,0,0);

Log.d("fff","Color 0 === "+c0);
Log.d("fff","Color 1 === "+c1);
Log.d("fff","Color 2 === "+c2);
Log.d("fff","Color 3 === "+c3);
Log.d("fff","Color 4 === "+c4);
Log.d("fff","Color 5 === "+c5);

打印LOG:

02-02 13:08:58.672 15085-15085/com.code.tx1n.tochat D/fff: Color 0 === #ffff0000
02-02 13:08:58.672 15085-15085/com.code.tx1n.tochat D/fff: Color 1 === -65536
02-02 13:08:58.672 15085-15085/com.code.tx1n.tochat D/fff: Color 2 === -65536
02-02 13:08:58.672 15085-15085/com.code.tx1n.tochat D/fff: Color 3 === 16711680
02-02 13:08:58.672 15085-15085/com.code.tx1n.tochat D/fff: Color 4 === -65536
02-02 13:08:58.672 15085-15085/com.code.tx1n.tochat D/fff: Color 5 === -65536

獲取Color的幾種方式