2

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>
Thinkcomplete
  • 181
  • 2
  • 7

1 Answers1

11

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

enter image description here

Jiang Qi
  • 4,450
  • 3
  • 19
  • 19
  • 6
    You can specify to draw the selector on top of the itemviews by setting `drawSelectorOnTop` to true (http://developer.android.com/reference/android/widget/AbsListView.html#attr_android:drawSelectorOnTop) – Jelle May 03 '13 at 14:29
  • 3
    @Jelle However the selector will cover the item text as well (so you will not see your items if you have opague selector) – Alex Semeniuk Sep 06 '13 at 09:42
  • Jelle & Alex both are right. In my case i have listview in which list item was totally cover with a imageview. So i need to show selector on top with given its opague . Ex :- color - #80000000 ( light black color) – Rana.S Feb 14 '14 at 07:56