android submenu

 

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 existing Menu with addSubMenu(). This returns a SubMenu object (an extension ofMenu). You can then add additional items to this menu, with the normal routine, using the add() methods. For example:

Code:
  1. public boolean onCreateOptionsMenu(Menu menu) {  
  2.   boolean result = super.onCreateOptionsMenu(menu);  
  3.   //设置子菜单的名称
  4.   SubMenu fileMenu = menu.addSubMenu("File");  
  5.   SubMenu editMenu = 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.   
  13.   return result;  
  14. }  

 

你可能感兴趣的:(android,File,application,extension,menu)