Search code examples
androiddrop-down-menumenuandroid-actionbar

How to implement custom drop-down menu to actionbar in android


i am trying to implement drop down menus in in actionbar, ( the count of items may very in runtime). for eg: Google map has the one.

how to implement it in android. here how the menu i'm looking for. i.e if i click on R image button i want a a drop down menu. similarly if i tap on L, left side menu should come. any idea how to do? .

I dont want sliding at all, i want a dropdown menu.

enter image description here


Solution

  • Regarding the action bar's structure, you have two options for the left side and one for the right side.

    Left side:

    Enable Action bar drop-down navigation

     actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_LIST);
    

    or

    Add a custom View as navigational element via ActionBar#setCustomView(), a Spinner in your case.

    Right side:

    Add only one MenuItem to the action bar as a custom Action View, a Spinner in your case.