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
If you plan to use setTextAppearance you should know that it will overwrite the text color with the style inherited from the theme. So if you want to use both, set the color afterwards.
This works:
textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);
textView.setTextColor(Color.RED);
While this will cause your textcolor to be for instance white(for dark theme) or black(for the light theme):
textView.setTextColor(Color.RED);
textView.setTextAppearance(context, android.R.style.TextAppearance_Medium);
Contrary to this in XML the order is arbitrary.