I'm trying to find my activity's Action Bar's spinner so I can selectively show and hide it (setNavigationMode
does not work for my purposes). I tried this code, but the Action Bar doesn't appear to be in my activity's (which is an extension of SherlockFragmentActivity
) root view.
private View findActionBarSpinner() {
View rootView = findViewById(android.R.id.content).getRootView();
List<View> spinners = traverseViewChildren( (ViewGroup) rootView );
return findListNavigationSpinner(spinners); // implement according to your layouts
}
All I get for rootView is a FrameLayout containing the RelativeLayout defined in my layout file (with only the elements within). I don't see anything that looks like an Action Bar or a spinner, and and sure enough traverseViewChildren (in the link above) returns an empty list.
I also tried, in the spirit of this answer, View rootView = getWindow().getDecorView().findViewById(android.R.id.content).getRootView();
. The result was the same.
I'm making the call to findActionBarSpinner
inside onOptionsItemSelected
. (Though I can't access it, the action bar is fully visible and working properly at this point, so I doubt it's an issue of trying to access it at the wrong part of lifecycle.)
Any ideas?