Can I detect click/tap on the menu button of action bar, i.e. used to show overflow menu items?
By default it opens up the list with one item \"Settings\". Here is t
To detect the click on the overflow menu have such code:
@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);
}
@Override
public void onPanelClosed(int featureId, Menu menu) {
...
}
To detect click on menu items, in case you have a menu like that :
You should be able to detect the click in
onOptionsItemSelected
@Override
public boolean onOptionsItemSelected(MenuItem item) {
Log.w("ANDROID MENU TUTORIAL:", "onOptionsItemSelected(MenuItem item)");
// Handle item selection
switch (item.getItemId()) {
case R.id.menu2:
Toast.makeText(this, "Clicked: Menu No. 2", Toast.LENGTH_SHORT).show();
return true;
...
}