Reputation: 375
How to change foreground color of Recycler view when an item is selected ?
e.g All other items except the selected item needs to be with different foreground color.
Upvotes: 0
Views: 478
Reputation: 58934
You can do it with drawable selector.
Put bg.xml
in drawable folder.
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@color/background_selected" android:state_selected="true"/>
<item android:drawable="@color/background_unselected"/>
</selector>
Now set this instead of your background.
<TextView
....
android:background="@drawable/bg"
...
/>
You just need to set selected in your adapter.
textView.setSelected(true);
Upvotes: 1