私はActionBarSherlockを使用しています。私のアプリでは、アクション バーに 2 つのスピナーが必要なので、リスト ナビゲーションを使用し、カスタム ビューで 2 つ目のスピナーを追加します。
次のコードを使用して、スピナーをカスタム ビューに追加します。
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);
Android 4.0.3 では、すべてが完全に動作します。
Android 2.2 の動作:
リスト ナビゲーション スピナーは、Android 4.0.4 のように見えます (ドロップダウンとして)。ただし、カスタム ビューのスピナーは、スピナー ビューのクリック時にダイアログの代わりにドロップダウンを表示します。
そのため、Android 2.2 のカスタム ビューで Spinner をAndroid 4.0.4 のようにドロップダウンとして表示する必要があります。