Max Rasguido Max Rasguido - 1 month ago 9
Android Question

What is the state of a spinner when it's displaying a drop down list?

I am creating a spinner with a custom view, anyway I managed to show different drawables for when the spinner is inactive and also for when it's pressed, I would like to keep the pressed state drawable when the dropdown list shows. Here is mi XML file:

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true"
android:state_pressed="false"
android:drawable="@drawable/ComboBoxInactive" />
<item android:state_focused="true"
android:state_pressed="true"
android:drawable="@drawable/ComboBoxActive" />
<item android:state_focused="false"
android:state_pressed="true"
android:drawable="@drawable/ComboBoxActive" />
<item android:drawable="@drawable/ComboBoxInactive" />
</selector>


what state should I add for when it is displaying the dropdown? I want it to display ComboBoxActive drawable. I already tried adding this:

<item android:state_enabled ="false"
android:drawable="@drawable/ComboBoxActive"/>


Any idea of what the state is?

Answer Source

There is no android:state_dropdown_showing state. The only one state on spinner dropdown list is state_enabled="true"

You can use my selector to differentiate dropdown list state

<?xml version="1.0" encoding="UTF-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<!-- disabled state -->
<item android:state_enabled="false" android:drawable="@drawable/spinner_off"/>
<!-- pressed state -->
<item android:state_enabled="true" android:state_window_focused="true" android:state_pressed="true" android:drawable="@drawable/spinner_pressed"/>
<!-- unselected state -->
<item android:state_enabled="true" android:state_window_focused="true" android:drawable="@drawable/spinner_default"/>
<!-- dropdown list state -->
<item android:state_enabled="true" android:state_focused="true" android:drawable="@drawable/spinner_dropdown_list_is_shown"/>
<!-- default -->
<item android:drawable="@drawable/spinner_default"/>
</selector>

Don't forget to set setFocusable and setFocusableInTouchMode properties on spinner.