I've created a layout that contains a spinner and injected into the custom view of my action bar.
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Spinner
android:id="@+id/navigationSpinner"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center"
android:focusable="true"
android:focusableInTouchMode="true"
android:background="@drawable/actionbar_spinner_background" />
</RelativeLayout>
I want the actionbar_spinner_background to be a selector with two states - effectively when the spinner is open and when its closed - but I can't find any way of detecting this. I've been through each of the states (state_focused etc) and found only the following seems to work (because the drop down menu is a popup window), but the problem is that the spinner will change state when anything overlays my app, for example when the status bar is pulled down.
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:state_window_focused="false"
android:drawable="@drawable/actionbar_spinner_background_up" />
<item android:drawable="@drawable/actionbar_spinner_background_down" />
</selector>
I've also seen similar stackoverflow questions here and here, but they both refer to "android:state_dropdown_showing" which doesn't appear to have been available for a long time (as an aside, my min api level is 14), and also here, which might be a slightly different use case, but has no answer anyway.
The best plan I seem to be able to come up with at the moment is to override my activity's onWindowFocusChanged() event, check to see if the drop down menu window/layout is present, and then call setActivated() (or something similar to set a state) on the spinner view.