List of usage examples for android.view Menu getItem
public MenuItem getItem(int index);
From source file:Main.java
/** * Android doesn't fade out disabled menu item icons, so do it ourselves *//* w w w . ja v a 2 s .c o m*/ public static void fixupMenuAlpha(Menu menu) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); Drawable icon = item.getIcon(); if (icon != null) { icon.setAlpha(item.isEnabled() ? 255 : 64); } } }
From source file:com.github.chenxiaolong.dualbootpatcher.MenuUtils.java
public static void tintAllMenuIcons(Menu menu, int color) { for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); tintMenuItemIcon(item, color);//from w w w. ja v a 2 s . co m } }
From source file:org.tasks.ui.MenuColorizer.java
/** Sets a color filter on all menu icons, including the overflow button (if it exists) */ private static void colorMenu(final Menu menu, final int color) { for (int i = 0, size = menu.size(); i < size; i++) { final MenuItem menuItem = menu.getItem(i); colorMenuItem(menuItem, color);/* www . java 2 s . c o m*/ if (menuItem.hasSubMenu()) { final SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), color); } } } }
From source file:com.github.pennyfive.cinemafinlando.ui.activity.generic.DrawerActivity.java
private static void hideMenuItems(Menu menu) { for (int i = 0; i < menu.size(); i++) { menu.getItem(i).setVisible(false); }//from ww w . j av a 2 s . co m }
From source file:androidx.navigation.ui.NavigationUI.java
/** * Sets up a {@link NavigationView} for use with a {@link NavController}. This will call * {@link #onNavDestinationSelected(MenuItem, NavController)} when a menu item is selected. * The selected item in the NavigationView will automatically be updated when the destination * changes./*from www. j a v a 2s.co m*/ * * @param navigationView The NavigationView that should be kept in sync with changes to the * NavController. * @param navController The NavController that supplies the primary and secondary menu. * Navigation actions on this NavController will be reflected in the * selected item in the NavigationView. */ public static void setupWithNavController(@NonNull final NavigationView navigationView, @NonNull final NavController navController) { navigationView.setNavigationItemSelectedListener(new NavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { boolean handled = onNavDestinationSelected(item, navController, true); if (handled) { ViewParent parent = navigationView.getParent(); if (parent instanceof DrawerLayout) { ((DrawerLayout) parent).closeDrawer(navigationView); } } return handled; } }); navController.addOnNavigatedListener(new NavController.OnNavigatedListener() { @Override public void onNavigated(@NonNull NavController controller, @NonNull NavDestination destination) { Menu menu = navigationView.getMenu(); for (int h = 0, size = menu.size(); h < size; h++) { MenuItem item = menu.getItem(h); item.setChecked(matchDestination(destination, item.getItemId())); } } }); }
From source file:androidx.navigation.ui.NavigationUI.java
/** * Sets up a {@link BottomNavigationView} for use with a {@link NavController}. This will call * {@link #onNavDestinationSelected(MenuItem, NavController)} when a menu item is selected. The * selected item in the BottomNavigationView will automatically be updated when the destination * changes.//from w w w. j av a 2 s . c o m * * @param bottomNavigationView The BottomNavigationView that should be kept in sync with * changes to the NavController. * @param navController The NavController that supplies the primary menu. * Navigation actions on this NavController will be reflected in the * selected item in the BottomNavigationView. */ public static void setupWithNavController(@NonNull final BottomNavigationView bottomNavigationView, @NonNull final NavController navController) { bottomNavigationView .setOnNavigationItemSelectedListener(new BottomNavigationView.OnNavigationItemSelectedListener() { @Override public boolean onNavigationItemSelected(@NonNull MenuItem item) { return onNavDestinationSelected(item, navController, true); } }); navController.addOnNavigatedListener(new NavController.OnNavigatedListener() { @Override public void onNavigated(@NonNull NavController controller, @NonNull NavDestination destination) { Menu menu = bottomNavigationView.getMenu(); for (int h = 0, size = menu.size(); h < size; h++) { MenuItem item = menu.getItem(h); if (matchDestination(destination, item.getItemId())) { item.setChecked(true); } } } }); }
From source file:com.example.ray.firstapp.bottombar.MiscUtils.java
/** * A hacky method for inflating menus from xml resources to an array * of BottomBarTabs./* w w w. j a v a2 s .c om*/ * * @param activity the activity context for retrieving the MenuInflater. * @param menuRes the xml menu resource to inflate * @return an Array of BottomBarTabs. */ protected static BottomBarTab[] inflateMenuFromResource(Activity activity, @MenuRes int menuRes) { // A bit hacky, but hey hey what can I do PopupMenu popupMenu = new PopupMenu(activity, null); Menu menu = popupMenu.getMenu(); activity.getMenuInflater().inflate(menuRes, menu); int menuSize = menu.size(); BottomBarTab[] tabs = new BottomBarTab[menuSize]; for (int i = 0; i < menuSize; i++) { MenuItem item = menu.getItem(i); BottomBarTab tab = new BottomBarTab(item.getIcon(), String.valueOf(item.getTitle())); tab.id = item.getItemId(); tabs[i] = tab; } return tabs; }
From source file:me.henrytao.mdcore.core.MdCompat.java
public static void supportDrawableTint(Context context, Menu menu, Palette palette) { if (menu != null) { int i = 0; for (int n = menu.size(); i < n; i++) { supportDrawableTint(context, menu.getItem(i), palette); }//from w w w .j av a 2 s.c o m } }
From source file:com.silentcircle.common.util.ViewUtil.java
public static void tintMenuIcons(@NonNull Menu menu, final int color) { for (int i = 0; i < menu.size(); ++i) { final MenuItem item = menu.getItem(i); Drawable icon = item.getIcon();/*from w w w . ja v a2 s .c om*/ if (icon != null) { icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN); item.setIcon(icon); } } }
From source file:org.solovyev.android.widget.menu.CustomPopupMenuHelper.java
static void tintMenuItems(Context context, Menu menu, int from, int to) { final ColorStateList tintColorStateList = getTintColorStateList(context); if (tintColorStateList == null) { return;// ww w . j av a2 s . com } for (int i = from; i < to; i++) { final MenuItem item = menu.getItem(i); if (item instanceof MenuItemImpl) { tintMenuItem((MenuItemImpl) item, tintColorStateList); } } }