我希望我的表格行在我触摸它时突出显示并在之后立即返回其默认颜色,但我不明白为什么什么也没发生。可能只是 xml 文件中缺少的东西,或者是不可能的,但无论如何都有我的代码:
table_selector.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="true" android:state_pressed="true" android:state_selected="true" android:drawable="@drawable/selected_state" />
<item android:state_enabled="true" android:state_focused="true" android:state_activated="true" android:state_selected="true" android:drawable="@drawable/hover_state" />
<item android:state_enabled="false" android:drawable="@drawable/default_state" />
</selector>
(我的状态文件只是带有颜色的形状。)
detail_row.xml
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableValues"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:clickable="true"
android:drawable="@drawable/table_selector" >
<TextView
android:id="@+id/txtId"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="4dp"
android:layout_weight="0.1"
android:gravity="center"
android:textColor="#FFFFFF"
android:textSize="@dimen/dataSize" />
<View style="@style/VDivider" />
[...]
detail_table.xml
[...]
<ScrollView
android:id="@+id/scrollView1"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TableLayout
android:id="@+id/detailTable"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true" >
</TableLayout>
</LinearLayout>
</ScrollView>
希望有人能给我带来光明。谢谢 !