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(安卓)WIFI DEMO(扫描附近WIFI强度)
  4. Android分页控件xlistview
  5. android基础控件(3)BottomNavigationView+FragmentLayout实现底层
  6. android的一个编译问题
  7. Android名称、版本和API level的对应关系
  8. Android(安卓)SDcard 文件读写,RandomAccessFile操作
  9. android 创建快捷方式

随机推荐

  1. Android深入浅出系列课程---Lesson3 AAF1
  2. 在eclipse中查看android SDK的源代码
  3. Android(安卓)5.0 MaterialDesign Ripple
  4. 编译Android内核
  5. android 动态壁纸 3 解决 动态壁纸列表界
  6. 使用Bottom Navigation Activity实现Andr
  7. 【Android】android:windowSoftInputMode
  8. This Android(安卓)SDK requires Android
  9. Android中shape属性详解:(设置圆角、设置渐
  10. [Android(安卓)Training视频系列]1.1 Cre