Gigen
Gigen

Reputation: 19

State list drawable not working properly on pre-honeycomb versions

I'm making an application with checklists that primarily targets Android 4.0. There I use this selector as the background of my list item:

<?xml version="1.0" encoding="utf-8"?>
<selector
    xmlns:android="http://schemas.android.com/apk/res/android">

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

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

<item
    android:state_activated="true"
    android:drawable="@drawable/checklist_selector_selected" />

<item
    android:drawable="@android:color/transparent" />

"state_activated" seems to do the trick as the checked items do not stay visibly checked if I take that selector away. However, this only works on post-Honeycomb versions. Anything before that ignores state_activated (or state_checked and state_selected) and only accepts state_pressed (the lines color themselves when I touch them but do not stay colored afterwards). This is really confusing to me so I would appreciate any advice on the matter.

Thanks.

Upvotes: 0

Views: 1320

Answers (1)

Ted Hopp
Ted Hopp

Reputation: 234847

The android:state_activated attribute does not exist prior to Honeycomb. I suggest that you maintain two versions of the drawable: a default version in res/drawable that does not reference android:state_activated (or any other states that were introduced in Honeycomb) and a Honeycomb-and-later version in res/drawable-v11 that does.

Upvotes: 2

Related Questions