Android listselector not visible in custom listvie

2020-03-26 12:14发布

问题:

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(R.style.rose); 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

listSelector

<item   android:state_focused="true"
        android:state_pressed="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

<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>  
</style>

回答1:

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

http://android.cyrilmottier.com/?p=454