Is it possible to go from a Color to a hex value? i.e. I have some colors defined, but I want to pr...
c
Is it possible to go from a Color to a hex value? i.e. I have some colors defined, but I want to print out the hex value on top of the color for debugging so it would be nice to just be able to reference the Color and get the hex value.
a
Color.toArgb()
then print the int as a hex string
c
color.toArgb().toString(16)
đź‘€ 1
Ah Adam beat me to it
a
eh, yours was better copypasta
c
toString(16)
is admittedly going over my head. Will read into it. Never seen that before. lol
toString(16)
didn't work, but
toHexString()
did for what it's worth. Thanks. I actually had this originally but the IDE complained to me that toArgb is only allowed in 1.4.30 and I'm not on that yet.
z
toString(16)
means “convert to string in base-16”, “hex” just means base 16
👍 1
c
Probably going to sound dumb, but I stumbled upon this problem again today (trying to convert a color I have defined in compose into something human readable I can show on the screen.) I noticed my method I used before of toHexString actually came from okhttp, so I went back to try toString(16) (as it was rec'd in SO as well), but I end up with negative values. Am I missing something basic here?
1695 Views