Can I detect click/tap on the menu button of action bar, i.e. used to show overflow menu items?
By default it opens up the list with one item "Settings". Here is the screenshot:
Until now it is detecting click on "2" but I want to detect click on "1".
By default clicking on the overflow button shows the options menu, so i believe you should manage to intercept the event, then do what you want by overriding
Activity.onPrepareOptionsMenu
This was a little tricky since i couldn't find an id for overflow button, so i used this hack. In your
Activity
:If you have setup Toolbar and inflated menu correctly, just use these two function in
MainActivity
Setup toolbar in
onCreate
function ofMainActivity
And inflate your menu which is defined in xml file
my_menu.xml
Finally i found the solution. Override FragmentActivity.onKeyDown
To detect the click on the overflow menu have such code:
To detect click on menu items, in case you have a menu like that :
You should be able to detect the click in