我有一个ListView,每个项目都有一个TextView .
我想更改项目TextView颜色,例如,当用户单击该项目时 .
任何想法,例子或教程?
谢谢
使用list of states .
例如,在drawable文件夹中创建一个名为bg_states.xml的文件:
<?xml version="1.0" encoding="utf-8"?> <selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@color/blue" ></item> <item android:state_pressed="true" android:drawable="@color/blue" ></item> <item android:drawable="@color/black" /> </selector>
并将其定义为TextView的背景:
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:background="@drawable/bg_states"
尝试一下
v.setBackgroundColor(R.Color.Red);
在 onClick 方法中
onClick
2 回答
使用list of states .
例如,在drawable文件夹中创建一个名为bg_states.xml的文件:
并将其定义为TextView的背景:
尝试一下
在
onClick
方法中