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?
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?
I receive an error: 08-03 21:06:24.673: ERROR/AndroidRuntime(20231): java.lang.NumberFormatException: unable to parse '0x00C8FBFE' as integer
I am using the Android SDK for their setBackgroundColor(int color)
function, which takes - as you might have guessed - an integer color value.
This is the OPPOSITE of this question: How to convert a color integer to a hex String in Android?
I have the same problem that I found some color in form of
#AAAAAA
and I want to conver that into a form that android could make use of. I found that you can just use0xFFAAAAAA
so that android could automatically tell the color. Notice the firstFF
is tellingalpha
value. Hope it helpsTry this, create drawable in your resource...
then use...
with color... "#FFFFFF"
if the color is transparent use... setAlpha
mView1.setAlpha(x);
with x float 0-1 Ej (0.9f)Good Luck
Answer is really simple guys, in android if you want to convert hex color in to int, just use android Color class, example shown as below
this is for light gray color
Thats it and you will get your result.
I was facing the same problem. This way I was able to solved it. As CQM said, using Color.parseColor() is a good solution to this issue.
Here is the code I used:
In this case my target was to change the Button's text color (Button_C) when I change the color selection from my Preferences (color_prefs).
The real answer is this simplest and easiest ....