当前位置: 首页>>代码示例>>Java>>正文


Java MenuItemImpl.getSubMenu方法代码示例

本文整理汇总了Java中android.support.v7.view.menu.MenuItemImpl.getSubMenu方法的典型用法代码示例。如果您正苦于以下问题:Java MenuItemImpl.getSubMenu方法的具体用法?Java MenuItemImpl.getSubMenu怎么用?Java MenuItemImpl.getSubMenu使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.support.v7.view.menu.MenuItemImpl的用法示例。


在下文中一共展示了MenuItemImpl.getSubMenu方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: prepareMenuItems

import android.support.v7.view.menu.MenuItemImpl; //导入方法依赖的package包/类
/**
 * Flattens the visible menu items of {@link #mMenu} into {@link #mItems},
 * while inserting separators between items when necessary.
 */
private void prepareMenuItems() {
    if (mUpdateSuspended) {
        return;
    }
    mUpdateSuspended = true;
    mItems.clear();
    mItems.add(new NavigationMenuHeaderItem());

    int currentGroupId = -1;
    int currentGroupStart = 0;
    boolean currentGroupHasIcon = false;
    for (int i = 0, totalSize = mMenu.getVisibleItems().size(); i < totalSize; i++) {
        MenuItemImpl item = mMenu.getVisibleItems().get(i);
        if (item.isChecked()) {
            setCheckedItem(item);
        }
        if (item.isCheckable()) {
            item.setExclusiveCheckable(false);
        }
        if (item.hasSubMenu()) {
            SubMenu subMenu = item.getSubMenu();
            if (subMenu.hasVisibleItems()) {
                if (i != 0) {
                    mItems.add(new NavigationMenuSeparatorItem(mPaddingSeparator, 0));
                }
                mItems.add(new NavigationMenuTextItem(item));
                boolean subMenuHasIcon = false;
                int subMenuStart = mItems.size();
                for (int j = 0, size = subMenu.size(); j < size; j++) {
                    MenuItemImpl subMenuItem = (MenuItemImpl) subMenu.getItem(j);
                    if (subMenuItem.isVisible()) {
                        if (!subMenuHasIcon && subMenuItem.getIcon() != null) {
                            subMenuHasIcon = true;
                        }
                        if (subMenuItem.isCheckable()) {
                            subMenuItem.setExclusiveCheckable(false);
                        }
                        if (item.isChecked()) {
                            setCheckedItem(item);
                        }
                        mItems.add(new NavigationMenuTextItem(subMenuItem));
                    }
                }
                if (subMenuHasIcon) {
                    appendTransparentIconIfMissing(subMenuStart, mItems.size());
                }
            }
        } else {
            int groupId = item.getGroupId();
            if (groupId != currentGroupId) { // first item in group
                currentGroupStart = mItems.size();
                currentGroupHasIcon = item.getIcon() != null;
                if (i != 0) {
                    currentGroupStart++;
                    mItems.add(new NavigationMenuSeparatorItem(
                            mPaddingSeparator, mPaddingSeparator));
                }
            } else if (!currentGroupHasIcon && item.getIcon() != null) {
                currentGroupHasIcon = true;
                appendTransparentIconIfMissing(currentGroupStart, mItems.size());
            }
            if (currentGroupHasIcon && item.getIcon() == null) {
                item.setIcon(android.R.color.transparent);
            }
            NavigationMenuTextItem textItem = new NavigationMenuTextItem(item);
            textItem.needsEmptyIcon = currentGroupHasIcon;
            mItems.add(textItem);
            currentGroupId = groupId;
        }
    }
    mUpdateSuspended = false;
}
 
开发者ID:jruesga,项目名称:rview,代码行数:77,代码来源:DrawerNavigationMenuPresenter.java

示例2: prepareMenuItems

import android.support.v7.view.menu.MenuItemImpl; //导入方法依赖的package包/类
/**
 * Flattens the visible menu items of {@link #menu} into {@link #items}, while inserting
 * separators between items when necessary.
 */
private void prepareMenuItems() {
  if (updateSuspended) {
    return;
  }
  updateSuspended = true;
  items.clear();
  items.add(new NavigationMenuHeaderItem());

  int currentGroupId = -1;
  int currentGroupStart = 0;
  boolean currentGroupHasIcon = false;
  for (int i = 0, totalSize = menu.getVisibleItems().size(); i < totalSize; i++) {
    MenuItemImpl item = menu.getVisibleItems().get(i);
    if (item.isChecked()) {
      setCheckedItem(item);
    }
    if (item.isCheckable()) {
      item.setExclusiveCheckable(false);
    }
    if (item.hasSubMenu()) {
      SubMenu subMenu = item.getSubMenu();
      if (subMenu.hasVisibleItems()) {
        if (i != 0) {
          items.add(new NavigationMenuSeparatorItem(paddingSeparator, 0));
        }
        items.add(new NavigationMenuTextItem(item));
        boolean subMenuHasIcon = false;
        int subMenuStart = items.size();
        for (int j = 0, size = subMenu.size(); j < size; j++) {
          MenuItemImpl subMenuItem = (MenuItemImpl) subMenu.getItem(j);
          if (subMenuItem.isVisible()) {
            if (!subMenuHasIcon && subMenuItem.getIcon() != null) {
              subMenuHasIcon = true;
            }
            if (subMenuItem.isCheckable()) {
              subMenuItem.setExclusiveCheckable(false);
            }
            if (item.isChecked()) {
              setCheckedItem(item);
            }
            items.add(new NavigationMenuTextItem(subMenuItem));
          }
        }
        if (subMenuHasIcon) {
          appendTransparentIconIfMissing(subMenuStart, items.size());
        }
      }
    } else {
      int groupId = item.getGroupId();
      if (groupId != currentGroupId) { // first item in group
        currentGroupStart = items.size();
        currentGroupHasIcon = item.getIcon() != null;
        if (i != 0) {
          currentGroupStart++;
          items.add(new NavigationMenuSeparatorItem(paddingSeparator, paddingSeparator));
        }
      } else if (!currentGroupHasIcon && item.getIcon() != null) {
        currentGroupHasIcon = true;
        appendTransparentIconIfMissing(currentGroupStart, items.size());
      }
      NavigationMenuTextItem textItem = new NavigationMenuTextItem(item);
      textItem.needsEmptyIcon = currentGroupHasIcon;
      items.add(textItem);
      currentGroupId = groupId;
    }
  }
  updateSuspended = false;
}
 
开发者ID:material-components,项目名称:material-components-android,代码行数:73,代码来源:NavigationMenuPresenter.java

示例3: prepareMenuItems

import android.support.v7.view.menu.MenuItemImpl; //导入方法依赖的package包/类
/**
 * Flattens the visible menu items of {@link #mMenu} into {@link #mItems}, while inserting
 * separators between items when necessary.
 */
private void prepareMenuItems() {
  if (mUpdateSuspended) {
    return;
  }
  mUpdateSuspended = true;
  mItems.clear();
  mItems.add(new NavigationMenuHeaderItem());

  int currentGroupId = -1;
  int currentGroupStart = 0;
  boolean currentGroupHasIcon = false;
  for (int i = 0, totalSize = mMenu.getVisibleItems().size(); i < totalSize; i++) {
    MenuItemImpl item = mMenu.getVisibleItems().get(i);
    if (item.isChecked()) {
      setCheckedItem(item);
    }
    if (item.isCheckable()) {
      item.setExclusiveCheckable(false);
    }
    if (item.hasSubMenu()) {
      SubMenu subMenu = item.getSubMenu();
      if (subMenu.hasVisibleItems()) {
        if (i != 0) {
          mItems.add(new NavigationMenuSeparatorItem(mPaddingSeparator, 0));
        }
        mItems.add(new NavigationMenuTextItem(item));
        boolean subMenuHasIcon = false;
        int subMenuStart = mItems.size();
        for (int j = 0, size = subMenu.size(); j < size; j++) {
          MenuItemImpl subMenuItem = (MenuItemImpl) subMenu.getItem(j);
          if (subMenuItem.isVisible()) {
            if (!subMenuHasIcon && subMenuItem.getIcon() != null) {
              subMenuHasIcon = true;
            }
            if (subMenuItem.isCheckable()) {
              subMenuItem.setExclusiveCheckable(false);
            }
            if (item.isChecked()) {
              setCheckedItem(item);
            }
            mItems.add(new NavigationMenuTextItem(subMenuItem));
          }
        }
        if (subMenuHasIcon) {
          appendTransparentIconIfMissing(subMenuStart, mItems.size());
        }
      }
    } else {
      int groupId = item.getGroupId();
      if (groupId != currentGroupId) { // first item in group
        currentGroupStart = mItems.size();
        currentGroupHasIcon = item.getIcon() != null;
        if (i != 0) {
          currentGroupStart++;
          mItems.add(new NavigationMenuSeparatorItem(mPaddingSeparator, mPaddingSeparator));
        }
      } else if (!currentGroupHasIcon && item.getIcon() != null) {
        currentGroupHasIcon = true;
        appendTransparentIconIfMissing(currentGroupStart, mItems.size());
      }
      NavigationMenuTextItem textItem = new NavigationMenuTextItem(item);
      textItem.needsEmptyIcon = currentGroupHasIcon;
      mItems.add(textItem);
      currentGroupId = groupId;
    }
  }
  mUpdateSuspended = false;
}
 
开发者ID:google,项目名称:iosched,代码行数:73,代码来源:NavigationMenuPresenter.java


注:本文中的android.support.v7.view.menu.MenuItemImpl.getSubMenu方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。