Android: How to add a click listener to menu icon(

2019-06-23 23:20发布

The onOptionsItemSelected(MenuItem item) method can be used to identify a click on each menu item. But i need to have a listener that can identify the click on the menu title (3 vertical dots at the top right of action bar). How could i implement one?

2条回答
做个烂人
2楼-- · 2019-06-23 23:53

When you choose basic activity, you get that 3 dot menu with it.

You don't have to add any click listener to that button it is created automatically. Try to run the app in emulator to see the results.

You can edit the default items of that menu from (res>menu>menu_main.xml)

查看更多
劫难
3楼-- · 2019-06-24 00:05

You can override onMenuOpened(javadoc) on your activity.

查看更多
登录 后发表回答