I have a simple list with a listselector like so.
<ListView android:id="@+id/list" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:layout_below="@+id/round"
android:listSelector="#99000000" android:clickable="true" android:cacheColorHint="#00000000" android:background="#00000000">
</ListView>
As you can see android:listSelector=”#99000000″ but the “black alpha” color is applied to the entire list, not the selected item.
So this is what I have now but the entire list still turns black
::listview_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:state_focused="true"
android:drawable="@drawable/list_normal" />
<item android:state_pressed="true"
android:drawable="@drawable/list_pressed" />
<item android:state_focused="true"
android:drawable="@drawable/list_active" />
</selector>
::colors.xml
<resources>
<drawable name="list_normal">#96FFFFFF</drawable>
<drawable name="list_active">#66000000</drawable>
<drawable name="list_pressed">#CA000000</drawable>
</resources>
::the xml tag in my list
android:listSelector="@drawable/listview_background"
I had the same problem. I have a custom background image, and I don’t want to have to make variants of that background image because that would be tedious to represent all the different states.
So I want to do the obvious thing, have a semi-transparent bar that is overlayed on top of the focused listitem and when the user taps the “enter” key or whatever, it flashes to the pressed overlay color which is more striking and somewhat more opaque.
The solution was to stay away from any @color or @drawable that refers to a color inside listSelector. I created two 3×3 pixel .png files. Each saved with the gamma layer. In my case it’s two of the same color each mixed down in Gimp with a different transparency on the color layer. So when you select an item you get an overlay with 25% color, and when you press it you get a png with 50% color. I put them in my drawables as bg_list_item_pressed.png and bg_list_item_highlighted.png
Then I set my list selector to:
Then I added my listSelector attributes to my ListView in my layout xml:
Now it works exactly how I want it to work. Including using the D-pad to select a row, and click it with enter. Getting the highlighting and subsequent pressing colors exactly how they should be.