duanhong169 / ColorPicker

🎨 A color picker for Android. Pick a color using color wheel and slider (HSV & alpha).
Apache License 2.0
361 stars 82 forks source link

How do I get the hexadecimal equivalent of the color in onColorPicked? #14

Open rickyManalo opened 5 years ago

rescalon34 commented 4 years ago

Hi @rickyManalo you can convert the obtained color to Hexadecimal using: Integer.toHexString(color). I'm using the following function, maybe it can help you too.

val hexColor = "#" + Integer.toHexString(color).substring(2).toUpperCase()
Log.d("CONVERTEDHEXCOLOR", "hexcolor: " + hexColor)

output:

CONVERTEDHEXCOLOR: hexcolor: #FF93A5
rickyManalo commented 4 years ago

I already found that out. But it would be nice to have a built-in function for that thing because it's a really important data because we don't usually need what format the plugin gives to us on most cases.

Ad9an commented 3 years ago

Fixing Alpha issue String hexVal = String.format("#%06X", (0xFFFFFFFF & color)).toUpperCase();

int length=hexVal.length();
String withoutHash=hexVal.substring(1,length);

while (withoutHash.length()<=7)
{

    withoutHash="0"+withH;

}
hexVal ="#"+withoutHash;