@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);
MenuItem menuSys = menu.add(1001, 100, 1, "系統菜单");
menuSys.setTitle("菜单一"); /* 最多可以显示6个子菜单 */
MenuItem menuUser = menu.add(1001, 101, 1, "用户菜单");
menuUser.setTitle("菜单二");
menuUser.setShortcut('c', 'c'); /* 给菜单设置快捷键 */
MenuItem menuCust = menu.add(1001, 102, 1, "客户菜单");
menuCust.setTitle("菜单三");
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// TODO Auto-generated method stub
switch (item.getItemId()) {
case 100:
Toast.makeText(MainActivity.this, "选择了菜单一", 1).show();
Intent intent = new Intent(MainActivity.this, NextActivity.class);
item.setIntent(intent); /* 切换到第二个Activity */
break;
case 101:
Toast.makeText(MainActivity.this, "选择了菜单二", 1).show();
break;
case 102:
Toast.makeText(MainActivity.this, "选择了菜单三", 1).show();
break;
default:
break;
}
return super.onOptionsItemSelected(item);
}