Android: How to add a click listener to menu icon(3 dots at the top)?

梦想的初衷 提交于 2020-01-03 16:52:08

问题


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?


回答1:


You can override onMenuOpened(javadoc) on your activity.




回答2:


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)



来源:https://stackoverflow.com/questions/38191825/android-how-to-add-a-click-listener-to-menu-icon3-dots-at-the-top

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!