menu的创建及选择
Activity中实现如下两个方法,add(groupid,itemid,order,title)或者add(groupId, itemId, order, titleRes)
titleRes为资源id,可自定义菜单项的图标
item.getItemId()方法得到菜单项的id,case语句判断id分别处理
1 @Override
2 public boolean onCreateOptionsMenu(Menu menu) {
3 // TODO Auto-generated method stub
4 menu.add(0, 0, 0, "about");
5 menu.add(0, 1, 1, "exit");
6 return super.onCreateOptionsMenu(menu);
7 }
8
9 @Override
10 public boolean onOptionsItemSelected(MenuItem item) {
11 // TODO Auto-generated method stub
12 super.onOptionsItemSelected(item);
13 switch (item.getItemId()) {
14 case 0:
15 openOptionDialog();
16 break;
17 case 1:
18 exitOptionDialog();
19 break;
20 }
21 return true;
22 }
-------------------------------~问世间情为何物,敲敲代码停不住~
-------------------------------