How to set the color of a TextView in Android?

TextView.setTextColor() takes an int representing the color (eg. 0xFFF5DC49) and not the resource ID from the xml file. In an activity, you can do something like:

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

outside of an activity you’ll need a Context eg.

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

Leave a Comment