本文共 1006 字,大约阅读时间需要 3 分钟。
十六进制值:#00CCFF
int textcolor = Color.parseColor("#00CCFF");
根据id获取十六进制的值
public String getColorHex(int colorId, Context context){
该方法可用于根据资源ID获取对应的十六进制颜色值。首先,通过上下文获取指定ID的颜色值,然后将其转换为十六进制字符串。这样可以方便地在代码中使用颜色值,同时遵循规范。具体实现如下:
stringbuffer = new StringBuffer();
int color = context.getResources().getColor(colorId);
字节表示:'
int textcolor = Color.parseColor("#00CCFF");
public String getColorHex(int colorId, Context context){ • stringbuffer = new StringBuffer(); int color = context.getResources().getColor(colorId); stringbuffer .append("#"); stringbuffer .append(Integer.toHexString(Color.alpha(color))); stringbuffer .append(Integer.toHexString(Color.red(color))); stringbuffer .append(Integer.toHexString(Color.green(color))); stringbuffer .append(Integer.toHexString(Color.blue(color))); 返回结果即为对应的十六进制字符串。
转载地址:http://jhgez.baihongyu.com/