自定义listview高亮成效

自定义listview高亮效果
参考http://www.geekmind.net/2009/10/android-custom-listview-selector.html

1) Copy files from the Android SDK:
Go to android-sdk/platforms/android-1.6/data/res/drawable and copy the following .xml files to your project's /res/drawable folder:
list_selector_background.xml
list_selector_background_transition.xml
You also need the following 9-patch images from the same folder, because they're referenced by the above .xml-files. You have to copy them, because within the SDK they're not a public resource, which means you can't just access them through the 自定义listview高亮成效 android: namespace as you could do with other public resources.
list_selector_background_focus.9.png
list_selector_background_longpress.9.png
list_selector_background_pressed.9.png
list_selector_background_disabled.9.png

2) Edit the two xml files and add to all resource values, which are publicly accessible the "android:namespace"

In our case this is only the following item:

<item android:drawable="@android:color/transparent" android:state_window_focused="false"></item>

All the other elements can point to the local namespace, because we copied the resources (images) into our local project's /res/drawable/ folder.

3)修改点击高亮的效果:用自定义的图片代替list_selector_background_pressed.9.png
或者修改list_selector_background_transition.xml里值。

4)listview可以加入一个默认的背景:
listView.setBackgroundResource(R.color.white);

5)listview加入选择XML:
listView.setSelector(R.drawable.list_selector_background);