Skip to content Skip to sidebar Skip to footer

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 p

Solution 1:

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"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><!-- disabled state --><itemandroid:state_enabled="false"android:drawable="@drawable/spinner_off"/><!-- pressed state --><itemandroid:state_enabled="true"android:state_window_focused="true"android:state_pressed="true"android:drawable="@drawable/spinner_pressed"/><!-- unselected state --><itemandroid:state_enabled="true"android:state_window_focused="true"android:drawable="@drawable/spinner_default"/><!-- dropdown list state --><itemandroid:state_enabled="true"android:state_focused="true"android:drawable="@drawable/spinner_dropdown_list_is_shown"/><!-- default --><itemandroid:drawable="@drawable/spinner_default"/></selector>

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

Solution 2:

Based on Olef Koshkin answer I can add that if you want save changed state after click to spinner and return it to default only after close spinner you can use. It works for me.

<?xml version="1.0" encoding="utf-8"?><selectorxmlns:android="http://schemas.android.com/apk/res/android"><!-- disabled state --><itemandroid:drawable="@drawable/custom_spinner_inactive"android:state_enabled="false"/><!-- pressed state --><itemandroid:drawable="@drawable/custom_spinner_inactive"android:state_enabled="true"android:state_pressed="true"android:state_window_focused="true"/><!-- unselected state --><itemandroid:drawable="@drawable/custom_spinner_inactive"android:state_enabled="true"android:state_window_focused="true"/><!-- dropdown list state --><itemandroid:drawable="@drawable/custom_spinner_inactive"android:state_enabled="true"android:state_focused="true"/><!-- default --><itemandroid:drawable="@drawable/custom_spinner_active"/></selector>

In other cases I see blink of default state and I didn't like it.

Post a Comment for "What Is The State Of A Spinner When It's Displaying A Drop Down List?"