Menu的实例(多级菜单)

menu的菜单项是根据你的布局中超过六个都显示五个然后一个是现在在more(更多)中的来分级的。

Menu的实例(多级菜单)Menu的实例(多级菜单)

Menu的实例(多级菜单)

package com.android.activity; import android.app.Activity; import android.os.Bundle; import android.view.Menu; import android.view.MenuItem; import android.widget.Toast; public class TestMenu extends Activity { /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); } @Override public boolean onCreateOptionsMenu(Menu menu) { super.onCreateOptionsMenu(menu); getMenuInflater().inflate(R.menu.message_view_option, menu); return true; } @Override public boolean onOptionsItemSelected(MenuItem item) { switch (item.getItemId()) { case R.id.delete: Toast.makeText(this, "delete", Toast.LENGTH_SHORT).show(); break; case R.id.reply: Toast.makeText(this, "reply", Toast.LENGTH_SHORT).show(); break; case R.id.reply_all: Toast.makeText(this, "reply_all", Toast.LENGTH_SHORT).show(); break; case R.id.forward: Toast.makeText(this, "forward", Toast.LENGTH_SHORT).show(); break; case R.id.send_alternate: Toast.makeText(this, "send_alternate", Toast.LENGTH_SHORT).show(); break; case R.id.mark_as_unread: Toast.makeText(this, "mark_as_unread", Toast.LENGTH_SHORT).show(); break; case R.id.flag: Toast.makeText(this, "flag", Toast.LENGTH_SHORT).show(); break; case R.id.move: Toast.makeText(this, "move", Toast.LENGTH_SHORT).show(); break; case R.id.copy: Toast.makeText(this, "copy", Toast.LENGTH_SHORT).show(); break; default: return super.onOptionsItemSelected(item); } return true; } } <?xml version="1.0" encoding="utf-8" ?> - <menu xmlns:android="http://schemas.android.com/apk/res/android"> <item android:id="@+id/reply" android:alphabeticShortcut="r" android:title="reply" android:icon="@drawable/ic_menu_reply" /> <item android:id="@+id/reply_all" android:alphabeticShortcut="a" android:title="reply_all" android:icon="@drawable/ic_menu_reply_all" /> <item android:id="@+id/forward" android:alphabeticShortcut="f" android:title="forward" android:icon="@drawable/ic_menu_forward_mail" /> <item android:id="@+id/mark_as_unread" android:alphabeticShortcut="u" android:title="mark_as_unread" android:icon="@drawable/ic_menu_mark" /> <item android:id="@+id/delete" android:alphabeticShortcut="q" android:title="delete" android:icon="@drawable/ic_menu_delete" /> <item android:id="@+id/flag" android:alphabeticShortcut="s" android:title="flag" android:icon="@drawable/ic_menu_forward_mail" /> <item android:id="@+id/send_alternate" android:title="send_alternate" android:icon="@drawable/ic_menu_forward_mail" /> <item android:id="@+id/move" android:title="move" /> <item android:id="@+id/copy" android:title="copy" /> </menu>