Colton Idle

    Colton Idle

    1 year ago
    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.
    Adam Powell

    Adam Powell

    1 year ago
    Color.toArgb()
    then print the int as a hex string
    cb

    cb

    1 year ago
    color.toArgb().toString(16)
    Ah Adam beat me to it
    Adam Powell

    Adam Powell

    1 year ago
    eh, yours was better copypasta
    Colton Idle

    Colton Idle

    1 year ago
    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.
    Zach Klippenstein (he/him) [MOD]

    Zach Klippenstein (he/him) [MOD]

    1 year ago
    toString(16)
    means “convert to string in base-16”, “hex” just means base 16
    Colton Idle

    Colton Idle

    1 year ago
    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?