私は最終的に、次のコードを使用して、ICS スタイルのスピナーをタブ付きナビゲーション Sherlock Fragment の Android 2.3.x ActionBar に入れることができました。
ActionBar bar = getSherlockActivity().getSupportActionBar();
bar.setDisplayHomeAsUpEnabled(true);
int dropDownStyle = R.attr.actionDropDownStyle;
ArrayAdapter<String> someAdapter = new ArrayAdapter<String>(getSherlockActivity()
.getSupportActionBar().getThemedContext(), R.layout.sherlock_spinner_dropdown_item,
new String[] {
"Last 7 days", "Last month", "Last 6 months", "Last year"
});
IcsSpinner mySpinner = new IcsSpinner(getActivity(), null, dropDownStyle);
mySpinner.setAdapter(someAdapter);
mySpinner.setOnItemSelectedListener(new IcsAdapterView.OnItemSelectedListener() {
@Override
public void onItemSelected(IcsAdapterView<?> parent, View view, int position, long id) {
switch (position) {
//do stuff
}
}
@Override
public void onNothingSelected(IcsAdapterView<?> parent) {
// simulate a click on the first item of the spinner
//do stuff
}
});
bar.setCustomView(mySpinner);
bar.setDisplayShowCustomEnabled(true);
次のように表示されます。
ただし、次のタブでは、ActionBar に 2 つの ICS スピナーが必要です。(ABS を使用する前は、アクティビティにスピナーがあり、2 番目のスピナーのオプションは標準のオプション メニューにありました。)
2 番目の CustomView を追加しようとすると、次のように、最初のものを上書き (上書きしますか?) します (2 番目のフラグメントに両方を別の名前で追加します)。
ActionBar に 2 つの CustomView を設定することはできますか? または、間違ったツリーを表示していますか? では、ActionBar で 2 つの ICS スピナーを実現するにはどうすればよいでしょうか?