I am trying to override the behavior of the hardware menu button on Android to make it open the overflow menu in the ActionBar.
Thanks to this question, I am able to display the overflow menu in the ActionBar. But when I press the hardware menu button, the "normal" menu (at the bottom of the screen) opens instead, of the overflow menu.
I tried to change this by overriding the onKeyDown(int, KeyEvent) in my Activity, but it doesn't work.
if (keyCode == KeyEvent.KEYCODE_MENU) {
// I am extending android.support.v7.app.ActionBarActivity
this.getSupportActionBar().openOptionsMenu();
return true;
}
After investigating, it seems that getSupportActionBar() returns an instance of android.support.v7.internal.app.WindowDecorActionBar, which return false in openOptionsMenu() instead of opening the menu.
Is there an other way to achieve this? Maybe trigger a click on the overflow icon directly? But how can I access it?