Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert color names to its equivalent hex code?

I want to display the TextView's text at particular color in which i am getting from server. From server colors are coming in string format. Like "YELLOW", "BLUE", "RED", "PURPLE" etc. How can we set this color to textview's text.

Can anybody have any idea about this?

Thanks

like image 522
krish Avatar asked Jul 02 '15 12:07

krish


1 Answers

If the server cannot send hex format as Redwarp's comment says, you can do basic colours like this;

Color.parseColor("RED")

Docs

Parse the color string, and return the corresponding color-int. If the string cannot be parsed, throws an IllegalArgumentException exception. Supported formats are: #RRGGBB #AARRGGBB 'red', 'blue', 'green', 'black', 'white', 'gray', 'cyan', 'magenta', 'yellow', 'lightgray', 'darkgray', 'grey', 'lightgrey', 'darkgrey', 'aqua', 'fuschia', 'lime', 'maroon', 'navy', 'olive', 'purple', 'silver', 'teal'

or create a color.xml in the values resource folder and create the colour resources like this;

<color name="white">#FFFFFF</color>
like image 196
matty357 Avatar answered Sep 24 '22 11:09

matty357