Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to convert rgb color to hex color - kotlin

This is what I do

val color = String.format("0XFF%02x%02x%02x", r, g, b)

this returns me a string "0XFFhexcode" I want to convert it to long, to store it and then use it as a color

color.toLong()

I have the following error

java.lang.NumberFormatException: For input string: 0XFFhexcode
like image 310
chrrissoft Avatar asked Jan 25 '26 12:01

chrrissoft


1 Answers

This code might help you:

Integer.toHexString(Color.rgb(r, g, b))
like image 78
Siddharth Kumar Avatar answered Jan 28 '26 02:01

Siddharth Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!