Android : How to add a drop-down menu on any given actionbar icon

on Sunday, July 6, 2014


I have been trying to create a simple drop down menu when I click my action bar icon and have certain selections link to particular activities.


Something like this:


enter image description here


I've tried to follow this but no luck.


Android ActionBar ActionProvider submenu


How to add submenu items to ActionBar action in code?


Currently I have this as my Java code, but the drop down menu appears under my appname instead of the overflow icon:



public boolean onCreateOptionsMenu(Menu menu){
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
return true;
}



@Override
protected void onCreate(Bundle savedInstanceState) {
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
super.onCreate(savedInstanceState);

SpinnerAdapter adapter =
ArrayAdapter.createFromResource(this, R.array.actions,
android.R.layout.simple_spinner_dropdown_item);

// Callback
OnNavigationListener callback = new OnNavigationListener() {

String[] items = getResources().getStringArray(R.array.actions); // List items from res

@Override
public boolean onNavigationItemSelected(int position, long id) {

// Do stuff when navigation item is selected

Log.d("NavigationItemSelected", items[position]); // Debug

return true;

}

};

0 comments:

Post a Comment