Java Code Examples for android.view.SubMenu#getItem()
The following examples show how to use
android.view.SubMenu#getItem() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MainActivity.java From guarda-android-wallets with GNU General Public License v3.0 | 6 votes |
private void changeMenuFontFamily() { Menu m = mNavigationView.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); } }
Example 2
Source File: MainActivity.java From Loop with Apache License 2.0 | 6 votes |
private void formatMenuItems() { Menu menu = navigationView.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem mi = menu.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); } }
Example 3
Source File: MainDrawerMenu.java From 4pdaClient-plus with Apache License 2.0 | 6 votes |
public void setItemCheckable(String name) { SubMenu subMenu; MenuItem item; for (int i = 0; i < menu.size(); i++) { subMenu = menu.getItem(i).getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { item = subMenu.getItem(j); if (item.getTitle().equals(name)) { menu.getItem(prevSelectedGroup).getSubMenu().getItem(prevSelectedItem).setCheckable(false).setChecked(false); item.setCheckable(true).setChecked(true); prevSelectedGroup = i; prevSelectedItem = j; prefs.edit().putString("navItemTitle", name).apply(); return; } } } }
Example 4
Source File: HomeScreenFragment.java From ground-android with Apache License 2.0 | 5 votes |
private void updateSelectedProjectUI(int selectedIndex) { SubMenu subMenu = getProjectsNavItem().getSubMenu(); for (int i = 0; i < projects.size(); i++) { MenuItem menuItem = subMenu.getItem(i); menuItem.setChecked(i == selectedIndex); } }
Example 5
Source File: Main.java From Cook-It-Android-XML-Template with MIT License | 4 votes |
@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); }
Example 6
Source File: BottomSheetAdapterBuilder.java From SimplicityBrowser with MIT License | 4 votes |
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; }
Example 7
Source File: NavigationMenuPresenter.java From material-components-android with Apache License 2.0 | 4 votes |
/** * 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; }
Example 8
Source File: BottomSheetAdapterBuilder.java From BottomSheetBuilder with Apache License 2.0 | 4 votes |
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; }
Example 9
Source File: MenuSheetView.java From ThreePhasesBottomSheet with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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; } } } }
Example 10
Source File: MenuSheetView.java From bottomsheet with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * 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; } } } }