Android listselector not visible in custom listvie

2020-03-26 11:51发布

I have made a custom list having image and textview. On setting the styles, the selector is not visible. The style is invoked using setTheme(; in create method of Listactivity as the first call. However if no color is used as background (or background line in style is commented) then the orange selector is visible. But not when the background is


<item   android:state_focused="true"
        android:drawable="@drawable/list_selector_background_transition" />

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

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


<style name="rose">
    <item name="android:textColor">@color/pink</item>
    <item name="android:background">@color/rose</item>
    <item name="android:cacheColorHint">@color/rose</item>

    <item name="android:listSelector">@drawable/listitem_selector</item>  

2楼-- · 2020-03-26 12:01

Android first draws the ListView background as well as the dividers. Then, the system draws the list selector. Finally, ListView renders all itemviews on top of that. So the list selector will never be visible with opaque background set to itemviews

enter image description here

登录 后发表回答