把colors.xml文件里配置的颜色值转成string
2017-02-14 17:07
453 查看
有个需求是需要传十六进制色值到后台,因为颜色值都配置在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();
}
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();
}
相关文章推荐
- Android colors.xml 颜色配置文件
- Android之在string.xml配置文字颜色粗体等效果
- 定义一个colors.xml颜色资源文件
- 【spring boot logback】日志颜色渲染,使用logback-spring.xml自定义的配置文件后,日志没有颜色了
- 配置颜色文件color.xml
- Unity3d中有关配置表(文件)采用XML和String方法的读取和写入
- MyBatis中,传String类型参数到xml配置文件,并执行SQL语句后返回String类型的结果写法(jeesite)
- android颜色配置文件color.xml
- Android开发在string.xml文件中设置部分字体颜色大小
- Android中string.xml文件中设置部分字体颜色大小
- 2.5 创建颜色渐变效果(xml配置文件)
- Android开发在string.xml文件中设置部分字体颜色大小
- 定义一个colors.xml颜色资源文件
- Android开发在string.xml文件中设置部分字体颜色大小
- 安卓获取res下的资源文件:string字符串、color颜色、dimen尺寸、array数组、drawable图片和xml、anim/animator动画、raw媒体、assets资源
- MyBatis-xml配置SQL文件中,传入List数组、基本类型String、int……、与自定义类型的方法
- idea部署踩坑: ibatis中配置文件载入错误org.xml.sax.SAXParseException: The string "--" is not permitted
- Android开发在string.xml文件中设置部分字体颜色大小
- 收集整理的Android color.xml文件的颜色配置
- ibatis中配置文件载入错误org.xml.sax.SAXParseException: The string "--" is not permitted