Skip to content Skip to sidebar Skip to footer

Set Text Color For Textview Android

In the string.xml file i use the following tag '#0000ff' If I use textview1.setTextColor(Color.RED); it works, but when I use

Solution 1:

You can use

  textView1.setTextColor(getResources().getColor(R.color.mycolor))

or

  textview1.setBackgroundColor(Color.parseColor("#ffffff"));

or

    textview1.setBackgroundColor(Color.RED);

or

    textView1.setBackgroundColor(R.color.black);

Solution 2:

This may be easier:

TextViewtextresult= (TextView)findViewById(R.id.textView1);
textresult.setTextColor(Color.RED);

Solution 3:

you should use R.color.CodeColor. you are using R.string.CodeColor.

Solution 4:

try set color like this may helps you

txt.setTextColor(Color.rgb(0, 87, 48));

this is different way but it can change color , here need Red,Green,Blue Code to pass

Solution 5:

Define colors in colors.xml file like that:

<resources><colorname="CodeColor" >#0000ff</color></resources>

Then use color whatever you like in your code using: R.color.CodeColor

Good luck!

Post a Comment for "Set Text Color For Textview Android"