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

5
  • 1
    So you want the items there but not clickable? I think you need to be more precise with your purpose of this. Commented Dec 18, 2013 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. Commented Dec 18, 2013 at 16:59
  • @CommonsWare My UX designer want to know if someone clicked those three rectangles :) Commented Dec 18, 2013 at 17:32
  • I am not aware of a specific callback or anything that will be invoked just by tapping on that. Commented Dec 18, 2013 at 17:33
  • Try the solution at: Every time overflow menu is opened...u will get a callback This might help u.. Commented May 2, 2016 at 9:44

2 Answers 2

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

Sign up to request clarification or add additional context in comments.

Comments

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)

3 Comments

I don't know why but I could see this method called also on the activity creation... maybe it's a Sherlock only issue...
@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.
Actually I could distinguish the creation calls from user click calls by comparing the onPrepareOptionsMenu call time with the menu creation time. Thanks!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.