1

Is there any option to detect a click in overflow menu?

I don't want to detect clicking in particular items.

enter image description here

pixel
  • 24,905
  • 36
  • 149
  • 251
  • 1
    So you want the items there but not clickable? I think you need to be more precise with your purpose of this. – Pontus Backlund Dec 18 '13 at 16:19
  • The only thing in the overflow are "particular items". If you do not want to detect clicks on those, there is nothing left. – CommonsWare Dec 18 '13 at 16:59
  • @CommonsWare My UX designer want to know if someone clicked those three rectangles :) – pixel Dec 18 '13 at 17:32
  • I am not aware of a specific callback or anything that will be invoked just by tapping on that. – CommonsWare Dec 18 '13 at 17:33
  • Try the solution at: [Every time overflow menu is opened...u will get a callback](http://stackoverflow.com/a/25117096/3382236) This might help u.. – the_D May 02 '16 at 09:44

2 Answers2

3

As it was posted in this other question, you can do the following:

@Override
public boolean onMenuOpened(int featureId, Menu menu) {
    if(featureId == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR){
        Toast.makeText(this, "OPEN", Toast.LENGTH_SHORT).show();
    }
    return super.onMenuOpened(featureId, menu);
}

@Override
public void onPanelClosed(int featureId, Menu menu) {
    if(featureId == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR){
        Toast.makeText(this, "CLOSE", Toast.LENGTH_SHORT).show();
    }
    super.onPanelClosed(featureId, menu);
}

If you are inheriting from AppCompat. If not, the right constant to be used is Window.FEATURE_ACTION_BAR

Community
  • 1
  • 1
AlvaroSantisteban
  • 5,256
  • 4
  • 41
  • 62
0

Are you simply trying to detect when the options menu itself is made visible? If so, I believe the "onPrepareOptionsMenu" method on Activity is your best bet.

Prepare the Screen's standard options menu to be displayed. This is called right before the menu is shown, every time it is shown. You can use this method to efficiently enable/disable items or otherwise dynamically modify the contents.

The default implementation updates the system menu items based on the activity's state. Deriving classes should always call through to the base class implementation.

http://developer.android.com/reference/android/app/Activity.html#onPrepareOptionsMenu(android.view.Menu)

DigCamara
  • 5,540
  • 4
  • 36
  • 47
Eric Schlenz
  • 2,551
  • 20
  • 19
  • I don't know why but I could see this method called also on the activity creation... maybe it's a Sherlock only issue... – Elhanan Mishraky Jun 19 '14 at 14:04
  • @ElhananMishraky Very well could be. I haven't used ActionBarSherlock personally. Instead I've had great success just using the compatibility libraries. But good note Elhanan, for those that are using ABS. – Eric Schlenz Jun 19 '14 at 19:47
  • Actually I could distinguish the creation calls from user click calls by comparing the onPrepareOptionsMenu call time with the menu creation time. Thanks! – Elhanan Mishraky Jun 22 '14 at 11:12