- 注册时间
- 2011-3-22
- 最后登录
- 2013-6-27
- 在线时间
- 11644 小时
- 阅读权限
- 150
- 积分
- 62779
- 帖子
- 28923
- 精华
- 1
- UID
- 6
|
任何软件都有菜单。刚才练习了下,拿出来跟大家讨论讨论。
在当前Activity 重写 onCreateOptionsMenu、onOptionsItemSelected 方法。- @Override
- public boolean onCreateOptionsMenu(Menu menu) {
- // TODO Auto-generated method stub
- menu.add(0,0,1,"退出"); //添加菜单。 groupId 分组第几组,itemId 这组第几项,order 这组的循序,title 显示菜单的名字
- /* API注释
- * MenuItem android.view.Menu.add(int groupId, int itemId, int order, CharSequence title)
- public abstract MenuItem add (int groupId, int itemId, int order, CharSequence title)
- Since: API Level 1
- Add a new item to the menu. This item displays the given title for its label.
- Parameters
- groupId The group identifier that this item should be part of. This can be used to define groups of items for batch state changes. Normally use NONE if an item should not be in a group.
- itemId Unique item ID. Use NONE if you do not need a unique ID.
- order The order for the item. Use NONE if you do not care about the order. See getOrder().
- title The text to display for the item.
- Returns
- The newly added menu item.
- */
- return super.onCreateOptionsMenu(menu);
- }
-
- @Override
- public boolean onOptionsItemSelected(MenuItem item) {
- // TODO Auto-generated method stub
- if(item.getItemId()==0) //获取当前点击的项ID
- {
- SysUtil sysutil=new SysUtil(Index.this); //这里是我另外的退出程序。
- sysutil.exit();
- }
- return super.onOptionsItemSelected(item);
- }
复制代码 |
-
2
查看全部评分
-
|