[英]How to change the textview color of item listview when that item is on click?
I have a ListView and each item have a TextView. 我有一个ListView,每个项目都有一个TextView。
I would like change the item TextView color, for example, when user click in that item. 我想更改项目TextView颜色,例如,当用户单击该项目时。
any ideas, examples or tutorials? 任何想法,例子或教程?
thanks 谢谢
use a list of states . 使用状态列表 。
For example, create a file called bg_states.xml in your drawable folder an: 例如,在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>
and define it as a background for your TextView: 并将其定义为TextView的背景:
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/bg_states"
try it with 尝试一下
v.setBackgroundColor(R.Color.Red);
in your onClick
method 在你的onClick
方法中
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.