Question Detail

I want to set TextColor in my Java File How can i set TextView Color programmatically in Activity.

I can change Color in XML 

android:textColor="@color/whiteColor"

i have tried txtView.setTextColor(R.color.Red);

not Working this


Thread Reply

Hemant Sharma

- 11 months ago

If you want to add TextView Color Programmatically and that color can only RED You can use Android Default Color Class with Color Name like this

txtView.setTextColor(Color.RED);

or If You have any Customise Color

txtView.setTextColor(Color.parseColor("#00FFFF"));

If you want to  Use Color.xml files COLOR You can use

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

Hemant Sharma

- 11 months ago

If you want to add TextView Color Programmatically and that color can only RED You can use Android Default Color Class with Color Name like this

txtView.setTextColor(Color.RED);

or If You have any Customise Color

txtView.setTextColor(Color.parseColor("#00FFFF"));

If you want to  Use Color.xml files COLOR You can use

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