0

I want to know how this conversion could be done:

I've checked that the following instruction:

 int color= ((ColorDrawable)  dialog1.getButton(AlertDialog.BUTTON_POSITIVE).getBackground()).getColor();

Gives in some devices the result color=-12434878, it's checked that the color is equivalent to the HTML color #424242.

But point is I see no way for transforming from one to the other and neither I find any reference for this.

How could this be done?

Sebastian Simon
  • 18,263
  • 7
  • 55
  • 75
user2638180
  • 1,013
  • 16
  • 37
  • 1
    Can you check which colors correspond to the colors `#000000` and `#ffffff`? It seems, that you can just add 16⁶ to that value and convert it to a base-16 string. You need that in Java, right? – Sebastian Simon Jul 29 '18 at 01:36
  • Yes, exactly in Java, I've checked that #FFFFFF is -1 and #000000 is -16777216, now I can see the pattern, problem was that negative sign was confusing me. Thanks a lot for your tip. – user2638180 Jul 29 '18 at 01:44
  • 1
    I think you are looking for this : https://stackoverflow.com/a/6540378/614807 – Chirag Jul 29 '18 at 04:11

1 Answers1

2

Convert integer to hex String

Integer intColor = -12434878;
String hexColor = "#" + Integer.toHexString(intColor).substring(2);
Anisuzzaman Babla
  • 6,510
  • 7
  • 36
  • 53