Skip to main content

How to set the text color of TextView in code?

How to set the text color of TextView in code?


A1. java-By Color class

         text.setTextColor(Color.parseColor("#FFFFFF"));

A2.java-hexa formate

       myTextView.setTextColor(0xAARRGGBB);

A3.

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

A4.From Xml


Create a color.xml file in the values folder:

<?xml version="1.0" encoding="utf-8"?>
<resources>
    <color name="textbody">#ffcc33</color>

</resources>


Then in any XML file, you can set color for text using:

android:textColor="@color/textbody"




A5.

     holder.text.setTextColor(Color.rgb(200,0,0));
















Comments