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
I did this way: Create a XML file, called Colors in res/values folder.
My Colors.xml:
#cc0000
#4c4cff
#000000
#CFDBC5
#ffffff
#cccc00
#66b266
To get this colors from the xml file, I've used this code: valor it's a TextView, and ctx it's a Context object. I'm not using it from an Activity, but a BaseAdapter to a ListView. That's why I've used this Context Object.
valor.setTextColor(ctx.getResources().getColor(R.color.azul_credito));
Hope it helps.