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
Asked
Active
Viewed 1,947 times
1
-
3`#0AF` == `#00AAFF` . what else do you want ? – Raptor Apr 30 '13 at 07:22
-
i want it using coding of android – GOLDEE Apr 30 '13 at 07:23
-
1and what have you tried ? – Raptor Apr 30 '13 at 07:26
-
i doesnt find any clue how to do it – GOLDEE Apr 30 '13 at 07:27
-
This requires basic programming skills in Java, nothing else. If you don't have them, think twice about whether or not to proceed from here. – class stacker Apr 30 '13 at 07:32
-
@ClassStacker I know i can do it using java code ,but i just want to find any predefined method which can give me my required result ....here it is http://stackoverflow.com/questions/6539879/how-to-convert-a-color-integer-to-a-hex-string-in-android – GOLDEE Apr 30 '13 at 08:09
3 Answers
3
One way is:
String rgb = "#0AF";
String rrggbb = "#";
for (int i = 1; i < rgb.length(); i++) {
rrggbb += (rgb.charAt(i) + "" + rgb.charAt(i));
}

Sergey Glotov
- 20,200
- 11
- 84
- 98

Daryn
- 770
- 9
- 19
2
int newRgb = 17 * (((oldRgb & 0xF00) << 8) | ((oldRgb & 0xF0) << 4) | (oldRgb & 0xF));

Sergey Glotov
- 20,200
- 11
- 84
- 98

Dmitry Bychenko
- 180,369
- 20
- 160
- 215
0
String hexColor = String.format("#%06X", (0xFFFFFF & intColor));
thats what i was searching. It will ensure that color string always will be #RRGGBB.

Sergey Glotov
- 20,200
- 11
- 84
- 98

GOLDEE
- 2,318
- 3
- 25
- 49
-
1Oh really? I think it's obvious that this doesn't do what you asked for. – class stacker Apr 30 '13 at 08:38
-
@ClassStacker thanks for ur suggestions but i dont think u r a right person to tell me what i asked is wrong or right ...ok ...enjoy . \m/ – GOLDEE Apr 30 '13 at 12:06
-
Oh, am I not? That surprises me. Because Daryn and @Dmitry Bychenko spent their time on answers which are based on an interpretation of your question which matches mine. I'd call that a majority. But I presume you're just after as much free code as possible. And you're very young, that explains a lot. Farewell, my friend! – class stacker Apr 30 '13 at 12:22