Reputation: 2318
I have to convert a color string in the format #RGB to #RRGGBB like #0af To #RRGGBB now can any one help out here using android
Upvotes: 1
Views: 2135
Reputation: 768
One way is:
String rgb = "#0AF";
String rrggbb = "#";
for (int i = 1; i < rgb.length(); i++) {
rrggbb += (rgb.charAt(i) + "" + rgb.charAt(i));
}
Upvotes: 3
Reputation: 2318
String hexColor = String.format("#%06X", (0xFFFFFF & intColor));
thats what i was searching. It will ensure that color string always will be #RRGGBB.
Upvotes: 0
Reputation: 186668
int newRgb = 17 * (((oldRgb & 0xF00) << 8) | ((oldRgb & 0xF0) << 4) | (oldRgb & 0xF));
Upvotes: 2