A sub menu can be added within any menu, except another sub menu. These are very useful when your application has a lot of functions that may be organized in topics, like the items in a PC application's menu bar (File, Edit, View, etc.).

A sub menu is created by adding it to an existingMenuwithaddSubMenu(). This returns aSubMenuobject (an extension ofMenu). You can then add additional items to this menu, with the normal routine, using theadd()methods. For example:

Code:
  1. publicbooleanonCreateOptionsMenu(Menumenu){
  2. booleanresult=super.onCreateOptionsMenu(menu);
  3. //设置子菜单的名称
  4. SubMenufileMenu=menu.addSubMenu("File");
  5. SubMenueditMenu=menu.addSubMenu("Edit");
  6. //按对应的名称增加子菜单
  7. fileMenu.add("new");
  8. fileMenu.add("open");
  9. fileMenu.add("save");
  10. editMenu.add("undo");
  11. editMenu.add("redo");
  12. returnresult;
  13. }

更多相关文章

  1. Android 菜单资源
  2. android仿优酷超炫菜单
  3. 【Android】Menu不同菜单的使用介绍
  4. Android Studio Gradle多渠道打包(动态设定App名称,应用图标,背景
  5. 开源项目之Android RibbonMenu(导航菜单)
  6. Android 修改打包APP默认名称(app-release.apk)
  7. 根据文件名称修改安卓默认的蓝牙接收文件地址
  8. flutter包名、应用名称、图标、启动图片修改
  9. 下拉选择菜单Spinner的使用

随机推荐

  1. android 设置控件 圆角
  2. Android之SharedPreferences数据保存
  3. Ubuntu 装 Courier New字体
  4. centos7中安装Android(安卓)SDK的方法步
  5. android中使用svg图标
  6. android4.2 屏蔽home键
  7. Android(安卓)开发过程网络相关问题
  8. Android(安卓)屏幕常亮
  9. Android定时器和倒计时实现淘宝秒杀功能
  10. android控件之spinner (下拉列表)