You can add spinner down menu in action Bar, for spinner, refer to Pro Android Learning Note (20): User interface and Control (8): GridView and Spinner. The style of the list is related to theme, and an exception can occur if the theme settings are incorrect.
The relevant code is as follows:
public class Listactionbardemo extends SEARCHTESTCASE3implements Onnavigationlistener{//list triggered callback function interface
@Override
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Workwithlistactionbar ();
}
protected void Workwithlistactionbar () {
ActionBar bar = Getactionbar ();
Bar.setnavigationmode (actionbar.navigation_mode_list); Must be set to list mode, so tab and list modes do not coexist
There is no difference between the adapter set spinner and the
arrayadapter<string> myadapter = new Arrayadapter<string> (This,
Android. R.layout.simple_spinner_item,
New string[]{"One", "one"});
Myadapter.setdropdownviewresource (Android. R.layout.simple_spinner_dropdown_item);
//Load Adpter, set callback function. The first function is the Spinneradatper interface, Arrayadapter has implemented the Spinneradatper GetView () function, which can be used directly
Bar.Setlistnavigationcallbacks(Myadapter, this);
}
@Override//list triggers the callback function, which is the example, simply log.
public boolean onnavigationitemselected (int itemposition, long itemId){
LOG.D ("Listmode", "List Select position" + itemposition + "itemId" + itemId);
return false;
}
}
The example code covered in this blog post can be downloaded in Pro Android Learning: Actionbar Small example.
RELATED Links: My Android development related articles
"Turn" Pro Android Learning Note (52): ActionBar (5): List mode