Example usage for android.view MenuItem getIcon

List of usage examples for android.view MenuItem getIcon

Introduction

In this page you can find the example usage for android.view MenuItem getIcon.

Prototype

public Drawable getIcon();

Source Link

Document

Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).

Usage

From source file:com.github.chenxiaolong.dualbootpatcher.MenuUtils.java

public static void tintMenuItemIcon(MenuItem item, int color) {
    Drawable drawable = item.getIcon();
    if (drawable != null) {
        Drawable wrapped = DrawableCompat.wrap(drawable);
        DrawableCompat.setTint(wrapped, color);
    }//from ww w  .  j  av  a 2s . com
}

From source file:Main.java

/**
 * Android doesn't fade out disabled menu item icons, so do it ourselves
 *//*from  w w w  .  ja v a2  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:org.tasks.ui.MenuColorizer.java

/** Sets a color filter on a {@link MenuItem} */
private static void colorMenuItem(final MenuItem menuItem, final int color) {
    colorDrawable(menuItem.getIcon(), color);
}

From source file:com.patloew.countries.ui.detail.DetailActivity.java

private static void tintMenuIcon(MenuItem menuItem) {
    Drawable favoriteIcon = DrawableCompat.wrap(menuItem.getIcon().mutate());
    DrawableCompat.setTint(favoriteIcon, 0xFFFFFFFF);
    menuItem.setIcon(favoriteIcon);//from  w w w .  j  ava  2 s.  c  o m
}

From source file:com.example.ray.firstapp.bottombar.MiscUtils.java

/**
 * A hacky method for inflating menus from xml resources to an array
 * of BottomBarTabs.//from www  .  ja  v  a2s.c o  m
 *
 * @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:android.support.v7.view.menu.MenuPopup.java

/**
 * Returns whether icon spacing needs to be preserved for the given menu, based on whether any
 * of its items contains an icon.//from  w  w w. ja v  a2s  .  c  o  m
 *
 * NOTE: This should only be used for non-overflow-only menus, because this method does not
 * take into account whether the menu items are being shown as part of the popup or or being
 * shown as actions in the action bar.
 *
 * @param menu
 * @return Whether to preserve icon spacing.
 */
protected static boolean shouldPreserveIconSpacing(MenuBuilder menu) {
    boolean preserveIconSpacing = false;
    final int count = menu.size();

    for (int i = 0; i < count; i++) {
        MenuItem childItem = menu.getItem(i);
        if (childItem.isVisible() && childItem.getIcon() != null) {
            preserveIconSpacing = true;
            break;
        }
    }

    return preserveIconSpacing;
}

From source file:com.joeyturczak.jtscanner.utils.Utility.java

public static void tintMenuIcon(Context context, MenuItem menuItem, int color) {
    Drawable drawable = menuItem.getIcon();

    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, ContextCompat.getColor(context, color));
    menuItem.setIcon(drawable);// w ww  .  ja  v a  2 s .  c o  m
}

From source file:com.kaliturin.blacklist.utils.Utils.java

/**
 * Tints menu icon//from   w w  w . j  av  a2s  .  co m
 **/
public static void setMenuIconTint(Context context, MenuItem item, @AttrRes int colorAttrRes) {
    Drawable drawable = DrawableCompat.wrap(item.getIcon());
    drawable.mutate();
    setDrawableTint(context, drawable, colorAttrRes);
}

From source file:me.henrytao.mdcore.core.MdCompat.java

public static void supportDrawableTint(Context context, MenuItem menuItem, Palette palette) {
    if (menuItem != null) {
        menuItem.setIcon(MdCompat.supportDrawableTint(context, menuItem.getIcon(), Palette.PRIMARY));
        if (menuItem.hasSubMenu()) {
            supportDrawableTint(context, menuItem.getSubMenu(), palette);
        }/*from w w w.  j  a  v a  2s  . c om*/
    }
}

From source file:com.nextgis.maplibui.util.ControlHelper.java

public static void setEnabled(MenuItem item, boolean state) {
    if (null == item)
        return;/*  w ww .ja  v a  2s  . c om*/
    item.setEnabled(state);
    item.getIcon().setAlpha(state ? 255 : 160);
}