Search code examples
androidandroid-optionsmenu

Android - Open a menu item automatically instead of showing drop down list


I got a menu with a single menu item. When I click the 3 dots menu icon in the action bar, a drop down list is opened to show the single item there is to choose.

How can I automatically handle that menu item as the user clicks the menu icon, without showing the drop down list (meaning the menu item should be chosen automatically for the user)?


Solution

  • You can use onMenuOpened to override the behavior:

    onMenuOpened

    added in API level 1 boolean onMenuOpened (int featureId, Menu menu) Called when a panel's menu is opened by the user. This may also be called when the menu is changing from one type to another (for example, from the icon menu to the expanded menu).