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
There are many different ways to set color on text view.
Add color value in studio res->values->colors.xml as
#800080
Now set the color in xml or actvity class as
text.setTextColor(getResources().getColor(R.color.color_purple)
If you want to give color code directly use below Color.parseColor code
textView.setTextColor(Color.parseColor("#ffffff"));
You can also use RGB
text.setTextColor(Color.rgb(200,0,0));
Use can also use direct hexcode for textView. You can also insert plain HEX, like so:
text.setTextColor(0xAARRGGBB);
You can also use argb with alpha values.
text.setTextColor(Color.argb(0,200,0,0));
a for Alpha (Transparent) v.
And if you're using the Compat library you can do something like this
text.setTextColor(ContextCompat.getColor(context, R.color.color_purple));