简体   繁体   English

android自定义列表视图背景焦点状态不起作用

[英]android Custom Listview Background Focus State not working

I am trying to create custom background selector for my ExpandableListView. 我正在尝试为我的ExpandableListView创建自定义背景选择器。 It works fine for all states other than focused. 它适用于除焦点以外的所有州。 I am unable to identify which row is currently focused. 我无法确定当前关注哪一行。 Here is the code: 这是代码:

im_selector.xml 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: 这就是为什么,对于listviews,你应该在你的选择器中添加像这样的行:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM