[ACCEPTED]-Setting TextView color to a <selector> programmatically-android-resources

Accepted answer
Score: 64

I think you might need to add findViewById or something 2 of that variety


Edit: the above is incorrect 1 as per my comment the proper answer is

setTextColor(getResources().getColorStateList(R.color.redeemlist_item_color));
Score: 42

You have to use getColorStateList()

I was also struggling with 4 this problem, if you want to have use a 3 state list, you need to declare it in the color resources 2 folder, instead of the drawable folder, and use 1 the setTextColor(getResources().getColorStateList(R.color.redeemlist_item_color)).

Score: 4

You can try:

holder.label.setTextColor(getResources().getColor(R.color.redeemlist_item_color));

instead 1 of :

holder.label.setTextColor(R.color.redeemlist_item_color);

Score: 0

Rasman is correct. You need to give the 4 TextView an ID, android:id="@+/something". You 3 retrieve a reference to that particular 2 using that ID and findViewById, and then 1 you may set the text color.

More Related questions