I have a ListView and each item have a TextView.
I would like change the item TextView color, for example, when user click in that item.
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:
<?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
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.