先新建一个selector
TextView必须加上下面几项属性,不然不能Click失效也不能获得焦点
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/btn_add_contact_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/btn_add_contact_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_add_contact_focused" />
<item android:state_enabled="true"
android:drawable="@drawable/btn_add_contact_normal" />
</selector>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_window_focused="false" android:state_enabled="true"
android:drawable="@drawable/btn_add_contact_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/btn_add_contact_pressed" />
<item android:state_focused="true" android:state_enabled="true"
android:drawable="@drawable/btn_add_contact_focused" />
<item android:state_enabled="true"
android:drawable="@drawable/btn_add_contact_normal" />
</selector>
TextView 设置
< TextView android:id = "@+id/view2" |
17 | android:layout_width = "fill_parent" |
18 | android:layout_height = "wrap_content" |
19 | android:text = "textview2" |
20 | android:clickable = "true" |
21 | android:focusable = "true" |
22 | android:focusableInTouchMode = "true" |
23 | android:background = "@drawable/list_item_selector" /> |
TextView必须加上下面几项属性,不然不能Click失效也不能获得焦点
android:clickable = "true" |
21 | android:focusable = "true" |
22 | android:focusableInTouchMode = "true" |