ListSelector applies to the entire list

I was having this same issue and while looking at one of the platform drawable XML files I noticed a way to eliminate the need to create an image file just for a color, by creating a shape in XML.

For example, instead of:

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

Do:

<item android:state_focused="true">
    <shape>
        <solid android:color="#66000000" />
    </shape>
</item>

Beyond just creating a plain color drawable, the shape is flexible, similar to a simple vector object. All the details can be found here: http://developer.android.com/guide/topics/resources/drawable-resource.html#Shape

Leave a Comment