StateListDrawable
I have a listView built in a ListActivity. I want the background of my rows to change when the item is pressed.
So I wrote in m开发者_开发问答y ListActivity : this.getListView().setSelector(R.drawable.my_custom_selector);
This is my_custom_selector.xml :
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true"
android:drawable="@drawable/selector" />
</selector>
drawable/selector is a selector.9.png
The problem is that nothing happens.
BUT : when I replace this drawable with a color all of the screen gets this color when I press a row.
Can you help me ?
Try to set your listview selector in .xml file for example in your listview
android:background="@drawable/your_selector"
here a small but good tutorials, check it. It also help you to solve your problem.
- Wrong code for setSelector of ListviewItem. You must define a listviewItem in xml and setSelector of it, instead of setSelector of ListView
精彩评论