简体   繁体   English

Android Hex颜色转换为Color

[英]Android Hex color to Color

I am facing an Issue converting Hex color #000 to Color or RGB . 我面临将十六进制颜色#000转换为ColorRGB Android Color.parseColor doesn't support shortened hex code. Android Color.parseColor不支持缩短的十六进制代码。

Please suggest the best solution. 请提出最佳解决方案。

I think best way is 我认为最好的方法是

int red = colorString.charAt(1) == '0' ? 0 : 255;
int blue = colorString.charAt(2) == '0' ? 0 : 255;
int green = colorString.charAt(3) == '0' ? 0 : 255;
Color.rgb(red, green,blue);

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM