How to set text color to a text view programmatically

Noby picture Noby · Dec 12, 2011 · Viewed 316.4k times · Source

How can I set Text Color of a text view to #bdbdbd programatically?

Answer

user370305 picture user370305 · Dec 12, 2011

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>));