Question about defining selector drawable

Put problem concerning Views, Layouts and other XML-Resources (like AndroidManifest) here.

Question about defining selector drawable

Postby silverburgh.meryl » Sat Feb 14, 2009 6:59 pm


I am trying to setup a selector drawable in my asset file like this:
* 2 different images for 'on'/'off' mode in rest mode (i.e. it does
not has focus)
* another 2 different images for 'on'/'off' mode in focus mode (i.e.
it has the focus).

In my case, the rest mode works, but the 'focus' mode does not.

Can you please tell me what am I missing in the focus mode? Thank you.

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="">

<!-- these 2 images works --->
<item android:state_checked="false" android:drawable="@drawable/off" />
<item android:state_checked="true" android:drawable="@drawable/on" />

<!-- these 2 images does not work -->
<item android:state_focused="true" android:state_checked="false"
android:drawable="@drawable/off_focus" />
<item android:state_focused="true" android:state_checked="true"
android:drawable="@drawable/on_focus" />

Junior Developer
Junior Developer
Posts: 23
Joined: Sun Feb 08, 2009 11:17 pm


Postby abraxas » Wed Feb 18, 2009 10:25 pm

You should try setting also the android:state_selected="true" attribute.

Syntax: [ Download ] [ Hide ]
Using xml Syntax Highlighting
  1. <item android:state_selected="true"
  3. android:state_pressed="false"
  5. android:drawable="@drawable/row_selected" />
Parsed in 0.000 seconds, using GeSHi

This should do the trick!
Junior Developer
Junior Developer
Posts: 20
Joined: Fri Feb 06, 2009 12:33 pm


Return to View, Layout & Resource Problems

Who is online

Users browsing this forum: No registered users and 5 guests