https://kotlinlang.org logo
#compose
Title
# compose
c

Colton Idle

02/10/2021, 8:27 PM
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

Adam Powell

02/10/2021, 8:32 PM
Color.toArgb()
then print the int as a hex string
c

cb

02/10/2021, 8:32 PM
color.toArgb().toString(16)
👀 1
Ah Adam beat me to it
a

Adam Powell

02/10/2021, 8:33 PM
eh, yours was better copypasta
c

Colton Idle

02/10/2021, 8:33 PM
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

Zach Klippenstein (he/him) [MOD]

02/10/2021, 8:47 PM
toString(16)
means “convert to string in base-16”, “hex” just means base 16
👍 1
c

Colton Idle

04/06/2021, 9:27 AM
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?
216 Views