android.view.Menu.addSubMenu()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(9.0k)|赞(0)|评价(0)|浏览(115)

本文整理了Java中android.view.Menu.addSubMenu()方法的一些代码示例,展示了Menu.addSubMenu()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Menu.addSubMenu()方法的具体详情如下:
包路径:android.view.Menu
类名称:Menu
方法名:addSubMenu

暂无

代码示例

代码示例来源:origin: alexvasilkov/GestureViews

private <T> void addSubMenu(Menu menu, T[] items, T selected, @StringRes int titleId) {
  SubMenu sub = menu.addSubMenu(titleId);
  sub.setGroupCheckable(Menu.NONE, true, true);
  for (int i = 0; i < items.length; i++) {
    MenuItem item = sub.add(Menu.NONE, titleId, i, items[i].toString());
    item.setCheckable(true);
    item.setChecked(items[i] == selected);
  }
}

代码示例来源:origin: stackoverflow.com

navView = (NavigationView) findViewById(R.id.navView);
 Menu m = navView.getMenu();
 SubMenu topChannelMenu = m.addSubMenu("Top Channels");
 topChannelMenu.add("Foo");
 topChannelMenu.add("Bar");
 topChannelMenu.add("Baz");

代码示例来源:origin: wangdan/AisenWeiBo

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
  super.onCreateOptionsMenu(menu, inflater);
  inflater.inflate(R.menu.menu_publish, menu);
  // 添加分组
  if (AppContext.getAccount().getGroups() == null || AppContext.getAccount().getGroups().getLists().size() == 0) {
  }
  else {
    SubMenu subMenu = menu.addSubMenu(R.id.publish, 333, 2,
                  GlobalContext.getInstance().getResources().getString(R.string.group_selected_visiable));
    for (int i = 0; i < AppContext.getAccount().getGroups().getLists().size(); i++) {
      Group group = AppContext.getAccount().getGroups().getLists().get(i);
      subMenu.add(100, i, i, group.getName());
    }
  }
}

代码示例来源:origin: ukanth/afwall

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  // Common options: Copy, Export to SD Card, Refresh
  SubMenu sub = menu.addSubMenu(0, MENU_TOGGLE, 0, "").setIcon(R.drawable.ic_flow);
  sub.add(0, MENU_CLEAR, 0, R.string.clear_log).setIcon(R.drawable.ic_clearlog);
  //sub.add(0, MENU_EXPORT_LOG, 0, R.string.export_to_sd).setIcon(R.drawable.exportr);
  //populateMenu(sub);
  sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  super.onCreateOptionsMenu(menu);
  mainMenu = menu;
  return true;
}

代码示例来源:origin: stackoverflow.com

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
   MenuInflater inflater = getMenuInflater();
   inflater.inflate(R.menu.main_activity_menu, menu);
   SubMenu submenu = menu.addSubMenu(0, Menu.FIRST, Menu.NONE, "Preferences");
   submenu.add(0, 10, Menu.NONE, "Get Last 5 Packets");
   submenu.add(0, 15, Menu.NONE, "Get Last 10 Packets");
   submenu.add(0, 20, Menu.NONE, "Get Last 20 Packets");
   inflater.inflate(R.menu.main_activity_menu, submenu);
   return true;
 }
 @Override
 public boolean onOptionsItemSelected(MenuItem item) {
   // Handle item selection
   switch (item.getItemId()) {
   case 10:
     Toast.makeText(LoginPageActivity.this, "Now "+item.getItemId(), Toast.LENGTH_SHORT).show();
     return true;
   case 15:
     Toast.makeText(LoginPageActivity.this, "Now = "+item.getItemId(), Toast.LENGTH_SHORT).show();
     return true;
   case 20:
     Toast.makeText(LoginPageActivity.this, "Now == "+item.getItemId(), Toast.LENGTH_SHORT).show();
     return true;
   default:
     return super.onOptionsItemSelected(item);
   }
 }

代码示例来源:origin: ukanth/afwall

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
  // Common options: Copy, Export to SD Card, Refresh
  SubMenu sub = menu.addSubMenu(0, MENU_TOGGLE, 0, "").setIcon(R.drawable.ic_flow);
  sub.add(0, MENU_CLEAR, 0, R.string.clear_log).setIcon(R.drawable.ic_clearlog);
  sub.add(0, MENU_SWITCH_OLD, 0, R.string.switch_old).setIcon(R.drawable.ic_log);
  //populateMenu(sub);
  sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS| MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  super.onCreateOptionsMenu(menu);
  mainMenu = menu;
  return true;
}

代码示例来源:origin: ukanth/afwall

@Override
public boolean onCreateOptionsMenu(android.view.Menu menu) {
  // Common options: Copy, Export to SD Card, Refresh
  SubMenu sub = menu.addSubMenu(0, MENU_TOGGLE, 0, "").setIcon(R.drawable.ic_flow);
  sub.add(0, MENU_ZOOM_IN, 0, getString(R.string.label_zoomin)).setIcon(R.drawable.zoomin).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
  sub.add(0, MENU_ZOOM_OUT, 0, getString(R.string.label_zoomout)).setIcon(R.drawable.zoomout).setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
  sub.add(0, MENU_COPY, 0, R.string.copy).setIcon(R.drawable.ic_copy);
  sub.add(0, MENU_EXPORT_LOG, 0, R.string.export_to_sd).setIcon(R.drawable.ic_export);
  sub.add(0, MENU_REFRESH, 0, R.string.refresh).setIcon(R.drawable.ic_refresh);
  populateMenu(sub);
  sub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  super.onCreateOptionsMenu(menu);
  mainMenu = menu;
  return true;
}

代码示例来源:origin: stackoverflow.com

SubMenu fileMenu = menu.addSubMenu("File");
SubMenu editMenu = menu.addSubMenu("Edit");
fileMenu.add(FILE, NEW_MENU_ITEM, 0, "new");
fileMenu.add(FILE, SAVE_MENU_ITEM, 1, "save");

代码示例来源:origin: stackoverflow.com

public Menu menuMain;
@Override
public boolean onCreateOptionsMenu(Menu menu) {
  menuMain = menu;
  subMenu = menu.addSubMenu(0, MENU_ID_1, 0, "Menu");
  subMenu.add(0, SUB_MENU_1, 0, getString(R.string.menu_settings));
  subMenu.add(0, SUB_MENU_2, 0, getString(R.string._new));
  menuItem = subMenu.getItem();
  menuItem.setIcon(R.drawable.menu_selector);
  menuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  return true;
}

代码示例来源:origin: stackoverflow.com

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
   menu.addSubMenu(0, 1, 1, " Button ").setIcon(R.drawable.file_icon)
     .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);;
   return true;
 }

代码示例来源:origin: stackoverflow.com

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  SubMenu fileMenu = menu.addSubMenu("File");
      fileMenu.add(FILE, NEW_MENU_ITEM, 0, "new");
  ...

代码示例来源:origin: com.actionbarsherlock/actionbarsherlock

@Override
public SubMenu addSubMenu(int titleRes) {
  return addInternal(mNativeMenu.addSubMenu(titleRes));
}

代码示例来源:origin: com.willowtreeapps/oak-demos

@Override
public SubMenu addSubMenu(int titleRes) {
  return addInternal(mNativeMenu.addSubMenu(titleRes));
}

代码示例来源:origin: Phantast/smartnavi

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  subMenu1 = menu.addSubMenu(0, 3, 3, "").setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_dark);
  subMenu1.add(0, 7, 7, getApplicationContext().getResources().getString(R.string.tx_65));
  MenuItem subMenu1Item = subMenu1.getItem();
  subMenu1Item.setIcon(R.drawable.ic_menu_moreoverflow_normal_holo_dark);
  subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
  return super.onCreateOptionsMenu(menu);
}

代码示例来源:origin: stackoverflow.com

public boolean onCreateOptionsMenu(Menu menu) {
super.onCreateOptionsMenu(menu);
SubMenu sub = menu.addSubMenu(0,1,0, "SubMenu");
sub.add(0,11,0,"SubMenu 1");
sub.add(0,12,0,"SubMenu 2");
sub.add(0,13,0,"SubMenu 3");
return true;
}

代码示例来源:origin: stackoverflow.com

public boolean onCreateOptionsMenu(Menu menu) {

SubMenu subMenu = menu.addSubMenu("Add");

subMenu.add("Add Subitem 1").setIcon(R.drawable.ic_action_add1);
subMenu.add("Add Subitem 2").setIcon(R.drawable.ic_action_add2);

MenuItem subMenu1Item = subMenu.getItem();
subMenu1Item.setIcon(R.drawable.ic_action_add);
subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

return super.onCreateOptionsMenu(menu);

}

代码示例来源:origin: stackoverflow.com

navView = (NavigationView) findViewById(R.id.navView);
 Menu m = navView.getMenu();
 SubMenu topChannelMenu = m.addSubMenu("Top Channels");
 topChannelMenu.add("Foo");
 topChannelMenu.add("Bar");
 topChannelMenu.add("Baz");

代码示例来源:origin: stackoverflow.com

@Override
 public boolean onCreateOptionsMenu(Menu menu) {
   super.onCreateOptionsMenu(menu);
   SubMenu subMenu1 = menu.addSubMenu("Action Item");
   subMenu1.add(0, 1, 0, "Sample");
   subMenu1.add(0, 2, 0, "Menu");
   subMenu1.add(0, 3, 0, "Sair");
   MenuItem subMenu1Item = subMenu1.getItem();
   subMenu1Item.setIcon(R.drawable.ic_title_share_default);
   subMenu1Item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS | MenuItem.SHOW_AS_ACTION_WITH_TEXT);
   return true;
 }

代码示例来源:origin: stackoverflow.com

mNavigationView = (NavigationView) context.findViewById(R.id.navigationView);
Menu menu = mNavigationView.getMenu();
SubMenu devicesMenu = menu.addSubMenu(Menu.NONE, DEVICES_MENU_ID, Menu.NONE, "Devices");
//You get your deviceId (nexus5Id, nexus6Id and so on) from your API call
//You should see deviceId in your code, from a loop or network callback
//in place of my hardcoded devices ids
devicesMenu.add(DEVICES_MENU_ID, nexus5Id, "Nexus 5");
devicesMenu.add(DEVICES_MENU_ID, nexus6Id, "Nexus 6");
devicesMenu.add(DEVICES_MENU_ID, nexus5XId, "Nexus 5X");
devicesMenu.add(DEVICES_MENU_ID, nexus6PId, "Nexus 6P");

代码示例来源:origin: IanDarwin/Android-Cookbook-Examples

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  MenuItem mi = menu.add("Main Menu, Option 1");
  mi.setShowAsAction(SHOW_AS_ACTION_IF_ROOM);
  SubMenu sub1 = menu.addSubMenu(GROUP_ID, ITEM_ID , Menu.NONE, R.string.submenu);
  sub1.setHeaderIcon(R.drawable.icon);
  sub1.setIcon(R.drawable.icon);
  sub1.add(GROUP_ID , OPTION_1, 0, "Submenu Option 1");
  sub1.add(GROUP_ID, OPTION_2, 1, "Submenu Option 2");
  return super.onCreateOptionsMenu(menu);
}

相关文章