textView设置按下和焦点改变时让字体颜色发生变化
在res/color/text_color_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/green" /> <item android:state_focused="true" android:color="@color/green" /> <item android:state_pressed="true" android:color="@color/green" /> <item android:color="@color/black"></item> </selector>
使用:
<TextView android:id="@+id/item_text" android:layout_width="fill_parent" android:layout_height="wrap_content" android:gravity="center" android:padding="2dip" android:textColor="@color/text_color_selector" android:textSize="12sp" />