开发者

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.


  1. Wrong code for setSelector of ListviewItem. You must define a listviewItem in xml and setSelector of it, instead of setSelector of ListView
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜