List of usage examples for android.view MenuItem hasSubMenu
public boolean hasSubMenu();
From source file:de.kuschku.util.ui.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/*w w w .j av a 2s .c o m*/ * <p> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> */ public void apply(Activity activity) { apply(); actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(() -> { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } }); }
From source file:locationkitapp.locationkit.locationkitapp.MapsActivity.java
@Override public boolean onOptionsItemSelected(MenuItem item) { Log.v(LOG_TAG, String.format("selected menu item %s", item.getTitle())); if (item.hasSubMenu()) { return true; }//from w w w. j a v a 2 s . c o m if (item.getItemId() == R.id.action_getplace) { getPlace(); return true; } if (item.getItemId() == R.id.action_clear) { clearVisits(); return true; } if (item.getItemId() == R.id.action_email) { emailVisitHistory(); return true; } if (item.getItemId() == R.id.action_enable_disable_notifications) { flipNotifications(item); return true; } if (item.getItemId() == R.id.action_enable_disable_tracking) { flipTracking(item); return true; } if (item.getItemId() == R.id.action_show_info) { String url = "https://locationkit.io/"; Intent i = new Intent(Intent.ACTION_VIEW); i.setData(Uri.parse(url)); startActivity(i); return true; } return super.onOptionsItemSelected(item); }
From source file:com.weebly.opus1269.copyeverywhere.ui.shared.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/*from w ww . j a v a2 s .co m*/ * <p/> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p/> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, menuItemIconColor, menuItemIconAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } }); }
From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>// w w w . j ava 2 s.c o m * <p> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (menu != null) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, iconsColor, iconsAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0; i < actionBarView.getChildCount(); i++) { final View v = actionBarView.getChildAt(i); //Step 1 : Changing the color of back button (or open drawer button). if (v instanceof ImageButton) { //Action Bar back button ((ImageButton) v).getDrawable() .setColorFilter(new PorterDuffColorFilter(iconsColor, PorterDuff.Mode.SRC_ATOP)); } } if (menu != null) { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, iconsColor, iconsAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), iconsColor, iconsAlpha); } } } if (iconsColor != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } } }); }
From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/*from w ww . j a v a2s .com*/ * <p/> * <p>Call this method after inflating/creating your menu in * {@link Activity#onCreateOptionsMenu(Menu)}.</p> * <p/> * <p>Note: This is targeted for the native ActionBar/Toolbar, not AppCompat.</p> * * @param activity the activity to apply the menu tinting on. */ public void apply(final Activity activity) { if (forceIcons) { forceMenuIcons(menu); } for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); colorMenuItem(item, menuItemIconColor, menuItemIconAlpha); if (reApplyOnChange) { View view = item.getActionView(); if (view != null) { if (item instanceof MenuItemImpl) { ((MenuItemImpl) item) .setSupportOnActionExpandListener(new SupportActionExpandListener(this)); } else { item.setOnActionExpandListener(new NativeActionExpandListener(this)); } } } } actionBarView = findActionBar(activity); if (actionBarView == null) { Log.w(LOG_TAG, "Could not find the ActionBar"); return; } // We must wait for the view to be created to set a color filter on the drawables. actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { overflowButton = findOverflowMenuButton(activity, actionBarView); colorOverflowMenuItem(overflowButton); } } }); }
From source file:com.adnanbal.fxdedektifi.forex.presentation.view.activity.SignalsActivity.java
private void uncheckAllMenuItems(NavigationView navigationView) { final Menu menu = navigationView.getMenu(); for (int i = 0; i < menu.size(); i++) { MenuItem item = menu.getItem(i); if (item.hasSubMenu()) { SubMenu subMenu = item.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { MenuItem subMenuItem = subMenu.getItem(j); subMenuItem.setChecked(false); }/* w w w . j av a 2 s . co m*/ } else { item.setChecked(false); } } }
From source file:org.thbz.hanguldrill.MainActivity.java
@Override public boolean onCreateOptionsMenu(Menu menu) { // Inflate the menu; this adds items to the action bar if it is present. getMenuInflater().inflate(R.menu.main_activity_actions, menu); try {//from www. j ava 2 s.c o m MenuItem configListItem = menu.findItem(R.id.action_configlist); String[] configIds = Settings.ConfigManager.getAllConfigIds(this); if (configListItem.hasSubMenu() && configIds.length > 0) { SubMenu configMenu = configListItem.getSubMenu(); if (configMenu == null) { if (BuildConfig.DEBUG) Log.d(TAG, "configMenu = null"); } else { // On ajoute une entre pour chacune des configurations existantes for (int i = 0; i < configIds.length; i++) { String configId = configIds[i]; Settings.Configuration config = Settings.ConfigManager.getConfigFromId(this, configId); String name = config.getName(this); configMenu.add(Menu.NONE, START_MENUITEM_ID + i, i, name); } } // Set configMenu title try { Settings.Configuration lastSelectedConfig = Settings.ConfigManager.getLastSelectedConfig(this); if (lastSelectedConfig != null) { String configName = lastSelectedConfig.getName(this); if (configName != null) { if (configName.length() > 15) configName = configName.substring(0, 13) + "\u2026"; configListItem.setTitle(configName); } } } catch (ClassCastException exc) { toastError("Exception : " + exc.getMessage()); } } } catch (InternalException exc) { if (BuildConfig.DEBUG) if (BuildConfig.DEBUG) Log.e(TAG, "Erreur interne", exc); } return super.onCreateOptionsMenu(menu); }
From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/*w ww .j a v a2 s . c o m*/ * <p> * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p> */ public void reapply() { if (menu != null) { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); if (isActionButton(item)) { colorMenuItem(menu.getItem(i), iconsColor, iconsAlpha); } } } if (actionBarView == null) { return; } actionBarView.post(new Runnable() { @Override public void run() { if (menu != null) { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, iconsColor, iconsAlpha); } else { colorMenuItem(menu.getItem(i), iconsColor, iconsAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), iconsColor, iconsAlpha); } } } } if (iconsColor != null || iconsAlpha != null) { colorOverflowMenuItem(overflowButton); } } }); }
From source file:de.kuschku.util.ui.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>/* www .ja v a 2 s . c o m*/ * <p> * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p> */ public void reapply() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); if (isActionButton(item)) { colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha); } } if (actionBarView == null) { return; } actionBarView.post(() -> { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } else { colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { colorOverflowMenuItem(overflowButton); } }); }
From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java
/** * <p>Sets a ColorFilter and/or alpha on all the {@link MenuItem}s in the menu, including the * OverflowMenuButton.</p>//from www . jav a 2s.c o m * <p/> * <p>This should only be called after calling {@link #apply(Activity)}. It is useful for when * {@link MenuItem}s might be re-arranged due to an action view being collapsed or expanded.</p> */ public void reapply() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem item = menu.getItem(i); if (isActionButton(item)) { colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha); } } if (actionBarView == null) { return; } actionBarView.post(new Runnable() { @Override public void run() { for (int i = 0, size = menu.size(); i < size; i++) { MenuItem menuItem = menu.getItem(i); if (isInOverflow(menuItem)) { colorMenuItem(menuItem, subMenuIconColor, subMenuIconAlpha); } else { colorMenuItem(menu.getItem(i), menuItemIconColor, menuItemIconAlpha); } if (menuItem.hasSubMenu()) { SubMenu subMenu = menuItem.getSubMenu(); for (int j = 0; j < subMenu.size(); j++) { colorMenuItem(subMenu.getItem(j), subMenuIconColor, subMenuIconAlpha); } } } if (menuItemIconColor != null || menuItemIconAlpha != null) { colorOverflowMenuItem(overflowButton); } } }); }