Yes, you can disable the Spinner used in list navigation in ActionBar . But this is not a simple solution, but a hack. ActionBar does not provide direct access to the Spinner view. Unfortunately, Spinner is created in personal code without any identifier.
So how to access a Spinner instance? One solution might be to access it through the Java reflection API, but I would not recommend this.
The best solution is to get the root view for the current Activity , cross its child views (the action bar and all its views are present in the view hierarchy) and find the correct Spinner . Since the Spinner in the action bar is apparently the only one that you did not create yourself, you should be able to distinguish it from others.
Getting the root of the View described in this SO question .
The workaround is quite simple, just keep in mind that if you use ActionBarSherlock , you need to look for IcsSpinner instead of Spinner ( IcsSpinner not distributed by Spinner ).
private View findActionBarSpinner() { View rootView = findViewById(android.R.id.content).getRootView(); List<View> spinners = traverseViewChildren( (ViewGroup) rootView ); return findListNavigationSpinner(spinners);
The findListNavigationSpinner function must be implemented in such a way that you can distinguish other spinners. If you are not using any Spinner (or any view derived from it), the returned list should contain only one element.
The code above describes how to get a Spinner in an Activity . Naturally, you should not disconnect Spinner from within Fragment . A fragment has a link to its activity, so an action can issue code to a fragment through some interface.
Tomik source share