android.view.SubMenu类的使用及代码示例

x33g5p2x  于2022-01-30 转载在 其他  
字(12.1k)|赞(0)|评价(0)|浏览(140)

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

暂无

代码示例

代码示例来源: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: Flipboard/bottomsheet

for (int i = 0; i < menu.size(); i++) {
  MenuItem item = menu.getItem(i);
  if (item.isVisible()) {
    if (item.hasSubMenu()) {
      SubMenu subMenu = item.getSubMenu();
      if (subMenu.hasVisibleItems()) {
        if (menuType == LIST) {
          items.add(SheetMenuItem.SEPARATOR);
        for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
          MenuItem subMenuItem = subMenu.getItem(subI);
          if (subMenuItem.isVisible()) {
            items.add(SheetMenuItem.of(subMenuItem));
        if (menuType == LIST && i != menu.size() - 1) {
          items.add(SheetMenuItem.SEPARATOR);

代码示例来源:origin: ankidroid/Anki-Android

@Override
public void onPrepareSubMenu(SubMenu subMenu) {
  subMenu.clear();
  getMenuInflater().inflate(R.menu.reviewer_schedule, subMenu);
  for (int i = 0; i < subMenu.size(); i++) {
    subMenu.getItem(i).setOnMenuItemClickListener(this);
  }
}

代码示例来源: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();
   for (int i=0;i<m.size();i++) {
     MenuItem mi = m.getItem(i);
     //for aapplying a font to subMenu ...
     SubMenu subMenu = mi.getSubMenu();
     if (subMenu!=null && subMenu.size() >0 ) {
       for (int j=0; j <subMenu.size();j++) {
         MenuItem subMenuItem = subMenu.getItem(j);
         applyFontToMenuItem(subMenuItem);
       }
     }
     //the method we have create in activity
     applyFontToMenuItem(mi);
   }

代码示例来源: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: konradrenner/kolabnotes-android

public void deleteNotebook(String notebookName){
  final SubMenu notebookSubmenu = view.getMenu().findItem(R.id.navigation_notebooks).getSubMenu();
  for(int i=0; i<notebookSubmenu.size(); i++){
    final int currentId = notebookSubmenu.getItem(i).getItemId();
    final String actualTitle = notebookSubmenu.getItem(i).getTitle().toString();
    if(actualTitle.equals(notebookName)){
      notebookSubmenu.removeItem(currentId);
    }
  }
}

代码示例来源:origin: mkulesh/microMathematics

activityResources = getResources().getStringArray(R.array.activity_resources);
for (int i = 0; i < navigationView.getMenu().size(); i++)
  final MenuItem m = navigationView.getMenu().getItem(i);
  if (m.getItemId() == R.id.nav_group_examples)
    for (int j = 0; j < Math.min(m.getSubMenu().size(), activitySubtitles.length); j++)
      final MenuItem m1 = m.getSubMenu().getItem(j);
      activityMenuItems.add(m1);
      m1.setTitle(activitySubtitles[m1.getOrder()]);
  else if (m.getItemId() == R.id.nav_group_etc)
    for (int j = 0; j < Math.min(m.getSubMenu().size(), activityTitles.length); j++)
      final MenuItem m1 = m.getSubMenu().getItem(j);
      activityMenuItems.add(m1);
      m1.setTitle(activityTitles[m1.getOrder()]);

代码示例来源:origin: derry/delion

@Override
public int getItemViewType(int position) {
  MenuItem item = getItem(position);
  int viewCount = item.hasSubMenu() ? item.getSubMenu().size() : 1;
  if (item.getItemId() == R.id.update_menu_id) {
    return UPDATE_MENU_ITEM;
  } else if (viewCount == 4) {
    return FOUR_BUTTON_MENU_ITEM;
  } else if (viewCount == 3) {
    return THREE_BUTTON_MENU_ITEM;
  } else if (viewCount == 2) {
    return TITLE_BUTTON_MENU_ITEM;
  }
  return STANDARD_MENU_ITEM;
}

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

sMenu.add(0, 4, 0, "SubOption1").setShortcut('5', 'z');
  sMenu.add(0, 5, 0, "SubOption2").setShortcut('5', 'z');             
public boolean onOptionsItemSelected(MenuItem item) {           
  switch (item.getItemId()) {
  case 0:

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

public void onPrepareSubMenu(SubMenu subMenu) {
  subMenu.clear();
    subMenu.add(0, i, i, activity.loadLabel(packageManager))
        .setIcon(activity.loadIcon(packageManager))
        .setOnMenuItemClickListener(mOnMenuItemClickListener);
    SubMenu expandedSubMenu = subMenu.addSubMenu(Menu.NONE, collapsedActivityCount,
        collapsedActivityCount,
        mContext.getString(R.string.abc_activity_chooser_view_see_all));
    for (int i = 0; i < expandedActivityCount; i++) {
      ResolveInfo activity = dataModel.getActivity(i);
      expandedSubMenu.add(0, i, i, activity.loadLabel(packageManager))
          .setIcon(activity.loadIcon(packageManager))
          .setOnMenuItemClickListener(mOnMenuItemClickListener);
    ActivityChooserModel dataModel = ActivityChooserModel.get(mContext,
        mShareHistoryFileName);
    final int itemId = item.getItemId();
    Intent launchIntent = dataModel.chooseActivity(itemId);
    if (launchIntent != null) {

代码示例来源:origin: 8enet/AppOpsX

final MenuItem searchMenu = menu.findItem(R.id.action_search);
final MenuItem settingsMenu = menu.findItem(R.id.action_setting);
final MenuItem premsMenu = menu.findItem(R.id.action_permission_sort);
menu.findItem(R.id.action_backup).setVisible(adapter != null && adapter.getItemCount() > 0);
 SubMenu userSub = menu.addSubMenu(R.id.action_users,Menu.NONE,Menu.NONE,R.string.action_users);
 userSub.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
 OnMenuItemClickListener menuItemClickListener = new OnMenuItemClickListener() {
  @Override
  MenuItem add = userSub.add(R.id.action_users,user.id,Menu.NONE,user.name);
  add.setCheckable(true);
  add.setChecked(user.id == users.getCurrentUid());
 userSub.setGroupCheckable(R.id.action_users,true,true);

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

menu.clear();
for (MenuItemImpl nonActionItem : nonActionItems) {
  if (!nonActionItem.isVisible()) {
    android.view.SubMenu nativeSub = menu.addSubMenu(nonActionItem.getGroupId(), nonActionItem.getItemId(),
        nonActionItem.getOrder(), nonActionItem.getTitle());
      android.view.MenuItem nativeSubItem = nativeSub.add(subItem.getGroupId(), subItem.getItemId(),
          subItem.getOrder(), subItem.getTitle());
      nativeSubItem.setIcon(subItem.getIcon());
      nativeSubItem.setOnMenuItemClickListener(listener);
      nativeSubItem.setEnabled(subItem.isEnabled());
      nativeSubItem.setIntent(subItem.getIntent());
      nativeSubItem.setNumericShortcut(subItem.getNumericShortcut());
        nativeSub.setGroupCheckable(subItem.getGroupId(), true, true);
    nativeItem = nativeSub.getItem();
  } else {
    nativeItem = menu.add(nonActionItem.getGroupId(), nonActionItem.getItemId(),
        nonActionItem.getOrder(), nonActionItem.getTitle());

代码示例来源:origin: towavephone/MemoryCleaner

@Override public boolean onCreateOptionsMenu(Menu menu) {
  // Inflate the menu; this adds items to the action bar if it is present.
  getMenuInflater().inflate(R.menu.menu_memory_clean, menu);
  SubMenu subMenu = menu.addSubMenu(GROUP_ID, BASE_ID, 0, "排序");
  subMenu.setIcon(R.drawable.ic_sort_white_24dp);
  subMenu.add(GROUP_ID + 1, BASE_ID + 1, 0, "应用名");
  subMenu.add(GROUP_ID + 1, BASE_ID + 2, 1, "大小");
  subMenu.add(GROUP_ID + 1, BASE_ID + 3, 2, "选中");
  subMenu.add(GROUP_ID + 2, BASE_ID + 4, 3, "降序")
      .setCheckable(true)
      .setChecked(true);
  subMenu.setGroupCheckable(GROUP_ID + 1, true, true);
  mMenuItem = menu.findItem(R.id.allcheck);
  ActionItemBadge.update(this, mMenuItem, FontAwesome.Icon.faw_check,
      ActionItemBadge.BadgeStyles.DARK_GREY, 0);
  return true;
}

代码示例来源:origin: billthefarmer/editor

@Override
public boolean onPrepareOptionsMenu(Menu menu)
  menu.findItem(R.id.edit).setVisible(!edit);
  menu.findItem(R.id.view).setVisible(edit);
  menu.findItem(R.id.save).setVisible(changed);
  menu.findItem(R.id.open).setVisible(isApp);
  menu.findItem(R.id.openRecent).setVisible(isApp);
  MenuItem item = menu.findItem(R.id.openRecent);
  SubMenu sub = item.getSubMenu();
  sub.clear();
               .getExternalStorageDirectory()
               .getPath() + File.separator, "");
    sub.add(name);

代码示例来源:origin: pockethub/PocketHub

private void setUpNavigationMenu() {
  MenuItem organizationContainer = navigationView.getMenu().findItem(R.id.navigation_organizations);
  if (organizationContainer.hasSubMenu()) {
    SubMenu organizationsMenu = organizationContainer.getSubMenu();
    for (int i = 1; i < orgs.size(); i++) {
      User organization = orgs.get(i);
      if (organizationsMenu.findItem(organization.id().intValue()) == null) {
        MenuItem organizationMenuItem = organizationsMenu.add(Menu.NONE, organization.id().intValue(), Menu.NONE, organization.name() != null ? organization.name() : organization.login());
        organizationMenuItem.setIcon(R.drawable.ic_github_organization_black_24dp);
        //Because of tinting the real image would became a grey block
        //avatars.bind(organizationMenuItem, organization);
        menuItemOrganizationMap.put(organizationMenuItem, organization);
      }
    }
  } else {
    throw new IllegalStateException("Menu item " + organizationContainer + " should have a submenu");
  }
}

代码示例来源:origin: konradrenner/kolabnotes-android

public void overrideTags(OnDrawerSelectionChangedListener listener, Collection<Tag> tags){
  final Menu overview = view.getMenu();
  final SubMenu tagSubmenu = overview.findItem(R.id.navigation_tags).getSubMenu();
  tagSubmenu.clear();
  for(Tag tag : tags){
    addTag(tagSubmenu, listener, tag);
  }
}

代码示例来源:origin: andresth/Kandroid

private void populateProjectsMenu() {
  if (mProjectList == null) {
    if (BuildConfig.DEBUG) Log.d("Kandroid", "Tried to populate drawer, but mDashboard was null");
    return;
  }
  SharedPreferences preferences = PreferenceManager.getDefaultSharedPreferences(this.getBaseContext());
  List<KanboardProject> projList = mProjectList;
  if (preferences.getBoolean("projects_sort_alphabetic", false))
    Collections.sort(projList);
  NavigationView nav = (NavigationView) findViewById(R.id.nav_view);
  SubMenu projMenu = nav.getMenu().findItem(R.id.projects).getSubMenu();
  projMenu.clear();
  for (KanboardProject item: projList)
    projMenu.add(Menu.NONE, item.getId(), Menu.NONE, item.getName())
        .setIcon(R.drawable.project);
}

代码示例来源:origin: zulip/zulip-android

@Override
  public void onBackStackChanged() {
    if (menu == null)
      return;
    if (narrowedList == null) {
      calendar = Calendar.getInstance();
      menu.findItem(R.id.filter).getSubMenu().getItem(0).setTitle(R.string.menu_today);
      switchToStream();
      checkForChatBoxFocusRequest();
    } else if (narrowedList.filter instanceof NarrowFilterByDate) {
      menu.findItem(R.id.filter).getSubMenu().getItem(0).setTitle(R.string.menu_one_day_before);
    }
  }
});

代码示例来源:origin: adamantoise/robocrosswords

@Override
public boolean onCreateOptionsMenu(Menu menu) {
  super.onCreateOptionsMenu(menu);
  System.setProperty("http.keepAlive", "false");
  utils.onActionBarWithText(menu.add(MENU_DOWNLOAD).setIcon(android.R.drawable.ic_menu_rotate));
  SubMenu sortMenu = menu.addSubMenu(MENU_SORT)
              .setIcon(android.R.drawable.ic_menu_sort_alphabetically);
  sortMenu.add(MENU_BYDATE_DESCENDING)
      .setIcon(android.R.drawable.ic_menu_day);
  sortMenu.add(MENU_BYDATE_ASCENDING)
      .setIcon(android.R.drawable.ic_menu_day);
  sortMenu.add(MENU_BYSOURCE)
      .setIcon(android.R.drawable.ic_menu_upload);
  sortMenu.add(MENU_BYAUTHOR)
      .setIcon(android.R.drawable.ic_menu_edit);
  utils.onActionBarWithText(sortMenu);
  menu.add(MENU_CLEANUP)
    .setIcon(android.R.drawable.ic_menu_manage);
  menu.add(MENU_ARCHIVES)
    .setIcon(android.R.drawable.ic_menu_view);
  menu.add(MENU_HELP)
    .setIcon(android.R.drawable.ic_menu_help);
  menu.add(MENU_SETTINGS)
    .setIcon(android.R.drawable.ic_menu_preferences);
  return true;
}

相关文章