转换十六进制颜色值(#FFFFFF)为整数值 [英] Convert hex color value ( #ffffff ) to integer value

查看:1906
本文介绍了转换十六进制颜色值(#FFFFFF)为整数值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我从服务器接收十六进制颜色值(以这种形式,#xxxxxx,例如#000000黑)

I am receiving hex color values from a server (in this form, #xxxxxx , example #000000 for black)

我要如何转换成一个整数值?

How do I convert this to an integer value?

我试图做 Integer.valueOf(0X+ passedColor.substring(1,passedColor.length()))来获得更hextastic 为0x000000 的结果,但这不是PTED为INTE $ P $的 INT 在这里,任何其他建议?

I tried doing Integer.valueOf("0x" + passedColor.substring(1, passedColor.length())) to get an even more hextastic 0x000000 result, but this isn't intepreted as an int here, any other suggestions?

我收到一个错误: 08-03 21:06:24.673:ERROR / AndroidRuntime(20231):java.lang.NumberFormatException:无法解析0x00C8FBFE作为整

我是使用Android SDK为他们的 setBackgroundColor(INT颜色)函数,该函数 - 正如你可能已经猜到了 - 一个整数颜色值

I am using the Android SDK for their setBackgroundColor(int color) function, which takes - as you might have guessed - an integer color value.

这是这个问题的反面:<一href="http://stackoverflow.com/questions/6539879/how-to-convert-a-color-integer-to-a-hex-string-in-android">How以颜色整数转换为Android的十六进制字符串?

this is the OPPOSITE of this question: How to convert a color integer to a hex String in Android?

推荐答案

真正的答案是使用

Col​​or.parseColor(myPassedColor)在Android中,myPassedColor是象#000 的十六进制值或#000000 #00000000

Color.parseColor(myPassedColor) in android, myPassedColor being the hex value like #000 or #000000 or #00000000

这篇关于转换十六进制颜色值(#FFFFFF)为整数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆