Avinash Prabhakar
Avinash Prabhakar

Reputation: 483

How to tell if Menu(Not menu item) is clicked?

for menu item I know I can use onOptionsSelected, but what function do I use if I want to know when the menu itself is clicked? (the 3 dots showed in the image below).

toolbar

Upvotes: 0

Views: 218

Answers (1)

Nongthonbam Tonthoi
Nongthonbam Tonthoi

Reputation: 12953

You don't have to set click listener to menu. Just override the following methods.

//Called on you open menu. or when you click on menu the three dots.
@Override
public boolean onMenuOpened(int featureId, Menu menu) {
   Toast.makeText(this, "Open", Toast.LENGTH_SHORT).show();
   return true;
}

You can also override this to detect close:

// Called when you close (ie. by clicking outside etc)
@Override
public void onPanelClosed(int featureId, Menu menu) {
    Toast.makeText(this, "closed", Toast.LENGTH_SHORT).show();
}

Upvotes: 2

Related Questions