i've found question (android 2.2 spinner looks old in actionbar) , tried it, isn't working me! want create spinner in sherlock actionbar, looks old in lower android versions. code:
oncreate:
@override protected void oncreate(bundle savedinstancestate) { super.oncreate(savedinstancestate); setcontentview(r.layout.activity_list); getsupportactionbar().setnavigationmode(actionbar.navigation_mode_list); }
oncreateoptionsmenu:
@override public boolean oncreateoptionsmenu(menu menu) { menuinflater mi = getsupportmenuinflater(); mi.inflate(r.menu.list, menu); final spinner spinner = new spinner(getsupportactionbar() .getthemedcontext()); arrayadapter<string> adapter = new arrayadapter<string>(getsupportactionbar().getthemedcontext(), r.layout.sherlock_spinner_item, new string[]{"level 1", "level 2", "level 3"}); adapter.setdropdownviewresource(r.layout.sherlock_spinner_dropdown_item); spinner.setadapter(adapter); spinner.setonitemselectedlistener(new onitemselectedlistener() { @override public void onitemselected(adapterview<?> arg0, view arg1, int arg2, long arg3) { // clicked } @override public void onnothingselected(adapterview<?> arg0) { // todo auto-generated method stub } }); menu.add("level").setactionview(spinner) .setshowasaction(menuitem.show_as_action_always); return true; }
that's because spinner
is old, , actionbarsherlock not affect behavior of spinner
.
if, instead of code, use setnavigationmode(actionbar.navigation_mode_list)
, drop-down list looks way want... not spinner
. rather, backport called icsspinner
part of actionbarsherlock's internal implementation. icsspinner
not part of actionbarsherlock public api afaik, though if poke around find people treating such anyway (running risk of apps breaking if jake wharton changes icsspinner
).
either:
use
setnavigationmode(actionbar.navigation_mode_list)
, ortry supported backport of holo-themed widgets, such holoeverywhere, or
pull out actionbarsherlock's
icsspinner
own code base, can maintain copy independently of changes made actionbarsherlock, oruse actionbarsherlock's own
icsspinner
directly, despite risks, orlive older , feel on older devices, or
don't use drop-down list in action bar on older devices
Comments
Post a Comment