In my application, I am using ActionBarSherlock 4.4.
Since ForcedOverflow has been removed from the latest version, I used the following XML code to replicate the OverflowMenu.
<menu xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:id="@+id/menu_overflow"
android:icon="@drawable/abs__ic_menu_moreoverflow_holo_dark"
android:orderInCategory="100"
android:showAsAction="always">
<menu>
<item
android:id="@+id/action_settings"
android:showAsAction="never"
android:title="@string/action_settings" />
<item
android:id="@+id/recycleBin"
android:showAsAction="never"
android:title="Recycle Bin" />
</menu>
</item>
</menu>
Overflow is working perfectly for me now, both for Android 4.3 and 2.3.3.
My problem :
The 2.3.3 device has a hardware Menu key. I want that when the Menu Key is pressed, the Overflow OptionsMenu should be opened.
I used the following code in Activity, but it doesn't work. (I am getting the messages in my LogCat though)
@Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
if (event.getAction() == KeyEvent.ACTION_UP &&
keyCode == KeyEvent.KEYCODE_MENU) {
Log.d("HomeActivity", "OpenOptionsMenu");
openOptionsMenu();
return true;
}
}
return super.onKeyUp(keyCode, event);
}
I looked around a lot, and tried all suggested solutions. But nowhere anyone is talking about opening a custom overflow menu using openOptionsMenu()
.
Am I missing something here?
Is there a way by which I can make it seem as if the parent overflow icon item android:id="@+id/menu_overflow"
has been clicked ?
It would be great if someone pointed out what I am missing out here.