In XML, we can set a text color by the textColor
attribute, like android:textColor=\"#FF0000\"
. But how do I change it by coding?
I tried s
You can do this only from an XML file too.
Create a color.xml
file in the values folder:
#ffcc33
Then in any XML file, you can set color for text using,
android:textColor="@color/textbody"
Or you can use this color in a Java file:
final TextView tvchange12 = (TextView) findViewById(R.id.textView2);
//Set color for textbody from color.xml file
tvchange1.setTextColor(getResources().getColor(R.color.textbody));