Paul Annekov
Paul Annekov

Reputation: 3263

Spinner dropdown style when using as custom view in ActionBarSherlock on Android 2.2

I'm using ActionBarSherlock. In my app I need 2 spinners in action bar so I use List Navigation + add second spinner with Custom View.

I add spinner to custom view with this code:

ActionBar bar = getSupportActionBar();

// FALLBACK: Use native actionbar dropdown style for 11+ API. Or use ActionBarSherlock style.
int dropDownStyle = (VERSION.SDK_INT < 11) ? R.attr.actionDropDownStyle : android.R.attr.actionDropDownStyle;           

MyAdapter someAdapter = new MyAdapter(this, list);          

Spinner mySpinner = new Spinner(this, null, dropDownStyle);                    
mySpinner.setAdapter(someAdapter);        
mySpinner.setOnItemSelectedListener(this);

bar.setCustomView(mySpinner);
bar.setDisplayShowCustomEnabled(true);

On Android 4.0.3 all works perfectly.

Android 2.2 behaviour:

List Navigation spinner looks like on Android 4.0.4 (as dropdown). But Spinner in Custom View displays Dialog instead dropdown on spinner view click.

So I need to display Spinner in custom view on Android 2.2 as dropdown like on Android 4.0.4.

enter image description here

Upvotes: 1

Views: 4944

Answers (1)

Jake Wharton
Jake Wharton

Reputation: 76075

ActionBarSherlock uses a custom spinner control, IcsSpinner, which provides the drop-down functionality. While this does exist in the internal package, it is a public class so you could switch your code to use that. This should give you an exact mirror of the drop-down used by the list navigation control.

However, keep in mind that this control has NOT been designed to be used anywhere but as the built-in list navigation and thus may be missing functionality or features you desire.

Upvotes: 6

Related Questions