In my application, I am using ActionBarSherlock 4.4.
Since ForcedOverflow has been removed from the latest version, I used the following XML to replicate 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 works great for me now, for both Android 4.3 and 2.3.3.
My problem:
Device 2.3.3 has a hardware menu. I want the menu overflow window to open when a menu key is pressed.
I used the following code in Activity, but it does not work. (I get 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 the proposed solutions. But nowhere is anyone talking about opening a custom overflow menu with openOptionsMenu() .
Am I missing something?
Is there any way by which I can make it look like I clicked the android:id="@+id/menu_overflow" parent overflow icon element android:id="@+id/menu_overflow" ?
It would be great if someone indicated what I missed here.
android actionbarsherlock android-optionsmenu submenu
Swayam Sep 21 '13 at 21:15 2013-09-21 21:15
source share