开发者

android Custom Listview Background Focus State not working

开发者 https://www.devze.com 2023-01-04 12:15 出处:网络
I am trying to create custom background selector for my ExpandableListView. It works fine for all states other than focused. I am unable to identify which row is currently focused. Here is the开发者_如

I am trying to create custom background selector for my ExpandableListView. It works fine for all states other than focused. I am unable to identify which row is currently focused. Here is the开发者_如何学Python code:

im_selector.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">

    <item android:state_focused="true"
        android:drawable="@drawable/list_selector_background_focus" />
    <item android:state_pressed="true"
        android:drawable="@drawable/list_selector_background_pressed" />

    <item 
        android:drawable="@drawable/list_bg" />

</selector>

my listview in the layout file

<ExpandableListView android:id="@+id/android:list"
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:scrollbars="horizontal"
              android:layout_below="@id/top_bar"
              android:layout_marginBottom="45px"
              android:divider="#00000000"
              android:cacheColorHint="#00000000"
              android:listSelector="@layout/im_selector"
              android:focusable="true"              
            />


When you use touch mode with listview, 'selected' attribute changes rather than 'focused'. That is why, for listviews you should add line like this one in your selector:

<item 
    android:state_selected="true" android:drawable="@drawable/list_selector_background_focus" />
0

精彩评论

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

关注公众号