获取Color的几种方式

#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

猜你喜欢

转载自www.cnblogs.com/xfdmyghdx/p/10348247.html
今日推荐