Search code examples
androidmenusubmenu

Open submenu in toolbar menu when I click a button in my layout


I have a menu with a lot of items and submenus and I would like to know if it is possible to open a submenu programmatically via click some button in the layout.

-menu
   -item1
   -item2
        -submenu
...

I want to open this "last" menu without clicking items in toolbar

I tried menu.findItem(R.id.item1).expandActionView() but it does nothing.


Solution

  • I solved adding the next code to my click listener:

    menu.performIdentifierAction(R.id.my_item, 0)