6

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

6
  • 2
    how many colors are we talking about ? Commented Jul 2, 2015 at 12:50
  • these colors can be anything, it's from server Commented Jul 2, 2015 at 12:51
  • if you have a limited number of colors then manage yourself with a class or with database with the name and code of color Commented Jul 2, 2015 at 12:53
  • 1
    You should ask the server to send you colors in hex format, like #1034f4, or 0x1034f4 Commented Jul 2, 2015 at 12:53
  • 1
    Better do the conversion on server-side and receive colors as int/hex values. If possible of course. Commented Jul 2, 2015 at 12:55

2 Answers 2

8

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> 
Sign up to request clarification or add additional context in comments.

Comments

0

Use this

textView.setTextColor(Color.parseColor("RED")); 

it will help you-

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.