1

What is the listener for click event of overflow icon in action bar?

It is not detected in the onoptions selected so where else it can be detected

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    // Handle action bar item clicks here. The action bar will
    // automatically handle clicks on the Home/Up button, so long
    // as you specify a parent activity in AndroidManifest.xml.
    int id = item.getItemId();
    Log.e("id  ", ""+id);

    if (id == R.id.action_settings) {
        return true;
    }

    return super.onOptionsItemSelected(item);
}
WISHY
  • 11,067
  • 25
  • 105
  • 197

1 Answers1

1

There is no onClick Listener for the overflow menu itself; only for items inside the menu. When you click on an element inside the overflow menu, onOptionsItemSelected() is called.

  • @Override public boolean onMenuOpened(int featureId, Menu menu) { if(featureId == AppCompatDelegate.FEATURE_SUPPORT_ACTION_BAR && menu != null){ //overflow menu clicked, put code here... } return super.onMenuOpened(featureId, menu); } – Anuj May 15 '22 at 15:01