Android 十六进制颜色值转换成int类型值

1.十六进制值:#00CCFF

int textcolor = Color.parseColor("#00CCFF")返回int数值;
text.setTextColor(textcolor);

2.根据id获取十六进制的值

public String getColorHex(int colorId, Context context){
        StringBuffer 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)));
        return stringbuffer .toString();
    }

你可能感兴趣的:(android)