本文整理汇总了Java中android.view.SubMenu.size方法的典型用法代码示例。如果您正苦于以下问题:Java SubMenu.size方法的具体用法?Java SubMenu.size怎么用?Java SubMenu.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.view.SubMenu
的用法示例。
在下文中一共展示了SubMenu.size方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: applyTypefaces
import android.view.SubMenu; //导入方法依赖的package包/类
private void applyTypefaces() {
Menu m = navigationView.getMenu();
for (int i = 0; i < m.size(); i++) {
MenuItem item = m.getItem(i);
//for applying a font to subMenu...
SubMenu subMenu = item.getSubMenu();
if (subMenu != null && subMenu.size() > 0) {
for (int j = 0; j < subMenu.size(); j++) {
MenuItem subMenuItem = subMenu.getItem(j);
applyTypeface(subMenuItem);
}
}
//the method we have create in activity
applyTypeface(item);
}
}
示例2: colorMenu
import android.view.SubMenu; //导入方法依赖的package包/类
/** Sets a color filter on all menu icons, including the overflow button (if it exists) */
public static void colorMenu(final Activity activity, final Menu menu, final int color,
final int alpha) {
for (int i = 0, size = menu.size(); i < size; i++) {
final MenuItem menuItem = menu.getItem(i);
colorMenuItem(menuItem, color, alpha);
if (menuItem.hasSubMenu()) {
final SubMenu subMenu = menuItem.getSubMenu();
for (int j = 0; j < subMenu.size(); j++) {
colorMenuItem(subMenu.getItem(j), color, alpha);
}
}
}
final View home = activity.findViewById(android.R.id.home);
if (home != null) {
home.post(new Runnable() {
@Override
public void run() {
colorOverflow(activity, color, alpha);
}
});
}
}
示例3: onCreate
import android.view.SubMenu; //导入方法依赖的package包/类
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setupToolbar(R.id.toolbar, "COOK IT", R.color.colorPink, R.color.colorWhiteTrans, R.drawable.ic_burger);
FragmentTransaction ft;
FragmentHome fragmentHome = new FragmentHome();
ft = getSupportFragmentManager().beginTransaction();
ft.replace(R.id.frameLayout, fragmentHome).commit();
drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
drawer.setDrawerListener(toggle);
toggle.syncState();
NavigationView navigationView = (NavigationView) findViewById(R.id.nav_view);
navigationView.setNavigationItemSelectedListener(this);
Menu m = navigationView.getMenu();
for (int i=0;i<m.size();i++) {
MenuItem mi = m.getItem(i);
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);
}
}
applyFontToMenuItem(mi);
}
View header = navigationView.getHeaderView(0);
ImageView imageView = (ImageView) header.findViewById(R.id.imageView);
Glide.with(this)
.load(Uri.parse("https://s3.amazonaws.com/uifaces/faces/twitter/jsa/128.jpg"))
.transform(new CircleGlide(this))
.into(imageView);
}
示例4: createAdapterItems
import android.view.SubMenu; //导入方法依赖的package包/类
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
int itemTextColor, int itemBackground,
int tintColor) {
List<BottomSheetItem> items = new ArrayList<>();
mTitles = 0;
boolean addedSubMenu = false;
for (int i = 0; i < mMenu.size(); i++) {
MenuItem item = mMenu.getItem(i);
if (item.isVisible()) {
if (item.hasSubMenu()) {
SubMenu subMenu = item.getSubMenu();
if (i != 0 && addedSubMenu) {
if (mMode == BottomSheetBuilder.MODE_GRID) {
throw new IllegalArgumentException("MODE_GRID can't have submenus." +
" Use MODE_LIST instead");
}
items.add(new BottomSheetDivider(dividerBackground));
}
CharSequence title = item.getTitle();
if (title != null && !title.equals("")) {
items.add(new BottomSheetHeader(title.toString(), titleTextColor));
mTitles++;
}
for (int j = 0; j < subMenu.size(); j++) {
MenuItem subItem = subMenu.getItem(j);
if (subItem.isVisible()) {
items.add(new BottomSheetMenuItem(subItem,itemTextColor, itemBackground, tintColor));
addedSubMenu = true;
}
}
} else {
items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
}
}
}
return items;
}
示例5: prepareMenuItems
import android.view.SubMenu; //导入方法依赖的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;
}
示例6: prepareMenuItems
import android.view.SubMenu; //导入方法依赖的package包/类
/**
* Flattens the visible menu items of {@link #menu} into {@link #items},
* while inserting separators between items when necessary.
*
* Adapted from the Design support library's NavigationMenuPresenter implementation
*/
private void prepareMenuItems() {
items.clear();
int currentGroupId = 0;
// Iterate over the menu items
for (int i = 0; i < menu.size(); i++) {
MenuItem item = menu.getItem(i);
if (item.isVisible()) {
if (item.hasSubMenu()) {
// Flatten the submenu
SubMenu subMenu = item.getSubMenu();
if (subMenu.hasVisibleItems()) {
if (menuType == LIST) {
items.add(SheetMenuItem.SEPARATOR);
// Add a header item if it has text
if (!TextUtils.isEmpty(item.getTitle())) {
items.add(SheetMenuItem.of(item));
}
}
// Add the sub-items
for (int subI = 0, size = subMenu.size(); subI < size; subI++) {
MenuItem subMenuItem = subMenu.getItem(subI);
if (subMenuItem.isVisible()) {
items.add(SheetMenuItem.of(subMenuItem));
}
}
// Add one more separator to the end to close it off if we have more items
if (menuType == LIST && i != menu.size() - 1) {
items.add(SheetMenuItem.SEPARATOR);
}
}
} else {
int groupId = item.getGroupId();
if (groupId != currentGroupId && menuType == LIST) {
items.add(SheetMenuItem.SEPARATOR);
}
items.add(SheetMenuItem.of(item));
currentGroupId = groupId;
}
}
}
}
示例7: createAdapterItems
import android.view.SubMenu; //导入方法依赖的package包/类
private List<BottomSheetItem> createAdapterItems(int dividerBackground, int titleTextColor,
int itemTextColor, int itemBackground,
int tintColor) {
List<BottomSheetItem> items = new ArrayList<>();
mTitles = 0;
boolean addedSubMenu = false;
for (int i = 0; i < mMenu.size(); i++) {
MenuItem item = mMenu.getItem(i);
if (item.isVisible()) {
if (item.hasSubMenu()) {
SubMenu subMenu = item.getSubMenu();
if (i != 0 && addedSubMenu) {
if (mMode == BottomSheetBuilder.MODE_GRID) {
throw new IllegalArgumentException("MODE_GRID can't have submenus." +
" Use MODE_LIST instead");
}
items.add(new BottomSheetDivider(dividerBackground));
}
CharSequence title = item.getTitle();
if (title != null && !title.equals("")) {
items.add(new BottomSheetHeader(title.toString(), titleTextColor));
mTitles++;
}
for (int j = 0; j < subMenu.size(); j++) {
MenuItem subItem = subMenu.getItem(j);
if (subItem.isVisible()) {
items.add(new BottomSheetMenuItem(subItem, itemTextColor,
itemBackground, tintColor));
addedSubMenu = true;
}
}
} else {
items.add(new BottomSheetMenuItem(item, itemTextColor, itemBackground, tintColor));
}
}
}
return items;
}
示例8: prepareMenuItems
import android.view.SubMenu; //导入方法依赖的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