How to check if drop down menu of ActionBar is active?

How to check if drop down menu of ActionBar is active

  • I'm using the ActionBar extending from the AppCompatActivity. How can I check, if the dropdown menu of the ActionBar is opened at the moment. I've tried it in this method. But it does not fire if I open the drop down menu: @Override public boolean onOptionsItemSelected(MenuItem item) { Intent intent = new Intent(); Log.i("ActionBar", "ActionBar dropdown is open at this moment"); switch (item.getItemId()) { case R.id.preferences: intent.setClass(StartupActivity.this, PreferencesActivity.class); startActivityForResult(intent, 0); return true; case R.id.info: intent.setClass(StartupActivity.this, InformationActivity.class); startActivityForResult(intent, 0); return true; case R.id.contact: intent.setClass(StartupActivity.this, ContactActivity.class); startActivityForResult(intent, 0); return true; default: return super.onOptionsItemSelected(item); } } It only fires, if I click on an item of the drop down menu. But I want to check, if the user clicks on the three-dot menu.

  • Answer:

    Try the following method: @Override public boolean onMenuOpened(int featureId, Menu menu) { // menu is open return super.onMenuOpened(featureId, menu); }

Stampy at Stack Overflow Visit the source

Was this solution helpful to you?

Other answers

I've tried this method, it works: @Override public boolean onPrepareOptionsMenu(Menu menu) { // menu open return super.onPrepareOptionsMenu(menu); } Even when initializing the menu, and not only when you click, but better than nothing.

Stampy

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.