I'm trying to get a TableRow, in a TableLayout, to change the background color when a user touches it, but it doesn't seem to be working. When I click on the TableRow, nothing happens. This what I have so far:
Layout:
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/BaseStyle"
android:stretchColumns="*">
<TableRow style="@style/TableRow">
<TextView
android:id="@+id/settings
style="@style/BaseStyle.SettingsText"
android:text="Settings"
android:onClick="onClick"
android:clickable="true"
/>
</TableRow>
</TableLayout>
Style:
<style name="TableRow">
<item name="android:background">@drawable/onclickhighlight</item>
</style>
Drawable (onclickhighlight.xml)
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- Active state -->
<item android:state_selected="true" android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/background_light" />
<!-- Inactive state-->
<item android:state_selected="false" android:state_focused="false" android:state_pressed="false" android:drawable="@android:color/transparent" />
<!-- Pressed state-->
<item android:state_selected="true" android:state_focused="true" android:state_pressed="true" android:drawable="@android:color/background_light" />
</selector>
Colors:
<resources>
<color name="background_light">#FFFFFF</color>
</resources>
I know the TableRow is using the onclickhighlight StateListDrawable because if I change the "Inactive state"s android:drawable property from @android:color/transparent, to @android:color/background_light, the background color changes to white.
I am having exactly the same issue and I'm trying to find the answer. I bet if you were to remove the
android:onClick="onClick"
from the table row xml, you'd find the highlight would work. But then, how would you get the click event to associate with the method you want?!