单击列表项时,我想更改文本颜色。
我在 res/color/textcolor_selector 中创建了选择器文件,但是单击 textview 时不会更改 textcolor
下面是我的代码
TextView textView = (TextView) view.findViewById(R.id.txt);
textView.setText(listArr[position]);
textView.setTextColor(getResources().getColor(R.color.textcolor_selector));
textcolor_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_selected="true" android:color="@color/selectedcolor" />
<item android:state_focused="true" android:color="@color/selectedcolor" />
<item android:state_pressed="true" android:color="@color/selectedcolor" />
<item android:color="@color/nonselectedcolor" />
</selector>