How to change the color integer value to hex String on Android

Asked 2 years ago, Updated 2 years ago, 108 views

An integer value was generated in android.graphics.Color. The integer value is -16776961. I'd like to change this value to #RRGGBB format for hexString. How shall I do it?

For example, I want to change -16776961 to #0000FFYo

android color hex java string

2022-09-22 22:10

1 Answers

String hexColor = String.format("#%06X", (0xFFFFFF & intColor)); You can do it in this way. %06x assigns the RRGGBB value to zero in hexadecimal format with 6 digits.


2022-09-22 22:10

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.