How to set text color to a text view programmatically [duplicate] How to set text color to a text view programmatically [duplicate] android android

How to set text color to a text view programmatically [duplicate]


Use,..

Color.parseColor("#bdbdbd");

like,

mTextView.setTextColor(Color.parseColor("#bdbdbd"));

Or if you have defined color code in resource's color.xml file than

(From API >= 23)

mTextView.setTextColor(ContextCompat.getColor(context, R.color.<name_of_color>));

(For API < 23)

mTextView.setTextColor(getResources().getColor(R.color.<name_of_color>));


Great answers. Adding one that loads the color from an Android resources xml but still sets it programmatically:

textView.setTextColor(getResources().getColor(R.color.some_color));

Please note that from API 23, getResources().getColor() is deprecated. Use instead:

textView.setTextColor(ContextCompat.getColor(context, R.color.some_color));

where the required color is defined in an xml as:

<resources>  <color name="some_color">#bdbdbd</color></resources>

Update:

This method was deprecated in API level 23. Use getColor(int, Theme) instead.

Check this.


yourTextView.setTextColor(color);

Or, in your case: yourTextView.setTextColor(0xffbdbdbd);