【Android】菜单功能的实现:使用XML
来源:互联网 发布:淘宝店家懒人软件 编辑:程序博客网 时间:2024/06/06 02:21
1.编辑Main对应菜单文件夹的xml文件:
<menu xmlns:android="http://schemas.android.com/apk/res/android" > <item android:id="@+id/action_settings" android:icon="@drawable/ic_launcher" android:orderInCategory="100" android:showAsAction="ifRoom|withText" android:title="@string/action_settings"> <menu> <item android:id="@+id/create_new" android:title="新建文件"> </item> <item android:id="@+id/open" android:title="打开文件"> </item> </menu> </item> <item android:id="@+id/sys" android:icon="@drawable/ic_launcher" android:orderInCategory="101" android:showAsAction="never" android:title="用户菜单"> <menu> <group android:id="@+id/group1" > <item android:id="@+id/load" android:title="加载文件"> </item> </group> <group android:id="@+id/group2" > <item android:id="@+id/save" android:title="保存文件"> </item> </group> </menu> </item></menu>
2.Main里面最重要还是那两个函数:
@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}@Overridepublic boolean onMenuItemSelected(int featureId, MenuItem item) {// TODO Auto-generated method stubswitch (item.getItemId()) {case R.id.create_new:Intent intent = new Intent(MainActivity.this, SystemMunu.class);item.setIntent(intent);break;case R.id.open:Toast.makeText(MainActivity.this, "打开菜单", Toast.LENGTH_SHORT).show();break;case R.id.load:Toast.makeText(MainActivity.this, "加载菜单", Toast.LENGTH_SHORT).show();break;case R.id.save:Toast.makeText(MainActivity.this, "保存菜单", Toast.LENGTH_SHORT).show();break;default:break;}return super.onMenuItemSelected(featureId, item);}
3.再创建一个Activity,就完成了。
注意这一句:
android:showAsAction="ifRoom|withText"
- 【Android】菜单功能的实现:使用XML
- Android菜单功能的实现
- 【Android】菜单功能的实现:上下文菜单
- 【Android】菜单功能的实现:使用Java代码
- Android使用Popupwindow实现悬浮菜单功能
- android之OptionsMenu功能菜单的使用
- 【Android】菜单功能的实现:弹出Popup菜单 以及小结
- android中菜单的使用(xml)
- android之使用ListView实现多菜单功能
- Android开发之使用DrawerLayout实现侧拉菜单功能
- Android 使用XML自定义菜单
- 【Android】菜单功能的实现:上下文action mode
- Android菜单的使用和实现
- android 自定义菜单 使用PopupWindow实现菜单的各种效果
- 功能菜单的实现代码
- 初学Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Android实现打电话的功能-使用Intent和AndroidManifset.xml中加入权限
- Chrome浏览器调用摄像头拍照
- DICT 和V$PARAMETER_VALID_VALUES
- django unexpected keyword argument 'use_decimal' 问题
- web 字符串处理
- 剑指Offer之二进制中1的个数
- 【Android】菜单功能的实现:使用XML
- swftools将PDF转成swf
- javascript函数原型
- wfp 驱动编译报错 解决方案.
- USACO Chapter1-Getting started Section 1.4
- BackToTop.js 为你的网站添加“回到顶部”按钮
- PLSQL执行sql的几种方法
- Android 实现三种动画与特效经典
- MFC 禁止应用程序多次运行