所以,事实证明这很简单,我最近在我的应用程序中实现了。
需要在溢出菜单中显示的项目,将它们嵌套在一个菜单项下,如下所示:
<menu xmlns:android="http://schemas.android.com/apk/res/android" >
<item
android:id="@+id/empty"
android:orderInCategory="101"
android:showAsAction="always"
android:icon="@drawable/ic_action_overflow">
<menu>
<item
android:id="@+id/action_settings"
android:orderInCategory="96"
android:showAsAction="never"
android:title="@string/menu_settings"
android:icon="@drawable/ic_action_settings"/>
<item
android:id="@+id/action_share"
android:orderInCategory="97"
android:showAsAction="never"
android:title="@string/menu_share"
android:icon="@drawable/ic_action_share"/>
<item
android:id="@+id/action_rate"
android:orderInCategory="98"
android:showAsAction="never"
android:title="@string/menu_rate"
android:icon="@drawable/ic_action_important"/>
<item
android:id="@+id/action_feedback"
android:orderInCategory="99"
android:showAsAction="never"
android:title="@string/menu_feedback"
android:icon="@drawable/ic_action_edit"/>
</menu>
</item>
</menu>
现在,编辑主活动文件,如下所示:
package com.example.test;
//all your import statements go here
Menu mainMenu=null;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState); }
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
mainMenu=menu;
return true; }
//Menu press should open 3 dot menu
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode==KeyEvent.KEYCODE_MENU) {
mainMenu.performIdentifierAction(R.id.empty, 0);
return true; }
return super.onKeyDown(keyCode, event); }