把colors.xml文件里配置的颜色值转成string

有个需求是需要传十六进制色值到后台,因为颜色值都配置在Colors.xml,所以需要转换一下,方法如下

colors.xml文件内容
<color name="style_color">#67ac66</color>


调用方法
changeColor(mContext,R.color.style_color)


/得到内容 67ac66
/
public String changeColor(Context context,int id){
StringBuffer stringBuffer = new StringBuffer();
int color = context.getResources().getColor(id);
int red = (color & 0xff0000) >> 16;
int green = (color & 0x00ff00) >> 8;
int blue = (color & 0x0000ff);

stringBuffer.append(Integer.toHexString(red)); stringBuffer.append(Integer.toHexString(green)); stringBuffer.append(Integer.toHexString(blue)); LogUtils.d("changecolor="+stringBuffer.toString()); return stringBuffer.toString(); }

相关文章

php输出xml格式字符串
J2ME Mobile 3D入门教程系列文章之一
XML轻松学习手册
XML入门的常见问题(一)
XML入门的常见问题(三)
XML轻松学习手册(2)XML概念