ColorPicker icon indicating copy to clipboard operation
ColorPicker copied to clipboard

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

Open rickyManalo opened this issue 4 years ago • 3 comments

rickyManalo avatar Jul 16 '19 07:07 rickyManalo

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

rescalon34 avatar Aug 04 '19 18:08 rescalon34

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.

rickyManalo avatar Aug 05 '19 01:08 rickyManalo

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;

Ad9an avatar Jul 04 '21 06:07 Ad9an