Android how to make View highlight when clicked? Android how to make View highlight when clicked? xml xml

Android how to make View highlight when clicked?


Ok I have finally figured out how to do this...basically it is done using a selector like the color selector linked by style except instead of 'color' use a drawable for the states and you can refer to the default list drawable that is used in ListView by this:

<selector xmlns:android="http://schemas.android.com/apk/res/android"><item android:state_pressed="true"    android:drawable="@android:drawable/list_selector_background" />      </selector>

and using this xml as the background for my View.

All the public default drawables can be found here: http://developer.android.com/reference/android/R.drawable.html


I was able to do the same with a text view that I wanted to behave like a list item by using:

<Textview....android:background="@android:drawable/list_selector_background"/>


This might be a good place to start looking.

Although, i would advise you to use the ListView itself, rather than implementing it again.