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.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();
        if (icon != null) {
            icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
            item.setIcon(icon);/*from  w w w .  j av  a  2  s  . co m*/
        }
    }
}

From source file:jahirfiquitiva.iconshowcase.utilities.color.ToolbarTinter.java

/**
 * Sets the color filter and/or the alpha transparency on a {@link MenuItem}'s icon.
 *
 * @param menuItem The {@link MenuItem} to theme.
 * @param color    The color to set for the color filter or {@code null} for no changes.
 *///  www .  ja  v a2s .  com
public static void colorMenuItem(MenuItem menuItem, Integer color, Integer alpha) {
    if (color == null) {
        return; // nothing to do.
    }
    Drawable drawable = menuItem.getIcon();
    if (drawable != null) {
        // If we don't mutate the drawable, then all drawables with this id will have the ColorFilter
        drawable.mutate();
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        if (alpha != null) {
            drawable.setAlpha(alpha);
        } else {
            drawable.setAlpha(255);
        }
    }
}

From source file:com.owncloud.android.datamodel.ThumbnailsCacheManager.java

private static GetAvatarTask getAvatarWorkerTask(MenuItem menuItem) {
    if (menuItem != null) {
        return getAvatarWorkerTask(menuItem.getIcon());
    }/*from   ww  w  .j ava  2s  . c  o  m*/
    return null;
}

From source file:de.grobox.liberario.utils.TransportrUtils.java

static public void fixToolbarIcon(Context context, MenuItem item) {
    item.setIcon(getToolbarDrawable(context, item.getIcon()));
}

From source file:com.weebly.opus1269.copyeverywhere.ui.shared.MenuTint.java

/**
 * Sets the color filter and/or the alpha transparency on a {@link MenuItem}'s icon.
 *
 * @param menuItem The {@link MenuItem} to theme.
 * @param color    The color to set for the color filter or {@code null} for no changes.
 * @param alpha    The alpha value (0...255) to set on the icon or {@code null} for no changes.
 *///from w w w. j  a  va  2s .  c o  m
public static void colorMenuItem(MenuItem menuItem, Integer color, Integer alpha) {
    if (color == null && alpha == null) {
        return; // nothing to do.
    }
    Drawable drawable = menuItem.getIcon();
    if (drawable != null) {
        // If we don't mutate the drawable, then all drawables with this id will have the ColorFilter
        drawable.mutate();
        if (color != null) {
            drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
        }
        if (alpha != null) {
            drawable.setAlpha(alpha);
        }
    }
}

From source file:co.carlosjimenez.android.currencyalerts.app.MenuTint.java

/**
 * Sets the color filter and/or the alpha transparency on a {@link MenuItem}'s icon.
 *
 * @param menuItem The {@link MenuItem} to theme.
 * @param color    The color to set for the color filter or {@code null} for no changes.
 * @param alpha    The alpha value (0...255) to set on the icon or {@code null} for no changes.
 *//*from   w  w w .ja  va2  s.c  o m*/
public static void colorMenuItem(MenuItem menuItem, Integer color, Integer alpha) {
    if (color == null && alpha == null) {
        return; // nothing to do.
    }
    Drawable drawable = menuItem.getIcon();
    if (drawable != null) {
        // If we don't mutate the drawable, then all drawables with this id will have the ColorFilter
        drawable.mutate();
        if (color != null) {
            drawable.setColorFilter(new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_ATOP));
        }
        if (alpha != null) {
            drawable.setAlpha(alpha);
        }
    }
}

From source file:com.android.contacts.group.GroupMembersFragment.java

private static void setVisible(Context context, Menu menu, int id, boolean visible) {
    final MenuItem menuItem = menu.findItem(id);
    if (menuItem != null) {
        menuItem.setVisible(visible);/*from   w  w w.  j  av a2s .c o  m*/
        final Drawable icon = menuItem.getIcon();
        if (icon != null) {
            icon.mutate().setColorFilter(ContextCompat.getColor(context, R.color.actionbar_icon_color),
                    PorterDuff.Mode.SRC_ATOP);
        }
    }
}

From source file:com.nextgis.maplibui.fragment.BottomToolbar.java

@Override
public void inflateMenu(@MenuRes int resId) {
    super.inflateMenu(resId);
    Menu menu = getMenu();//  w w  w .  j a va2  s  .c om
    MenuItem item = menu.getItem(0);
    int size = item.getIcon().getIntrinsicWidth() + ControlHelper.dpToPx(30, getResources());
    int width = getWidth();

    for (int i = 0; i < menu.size(); i++) {
        item = menu.getItem(i);
        if (size * (i + 2) < width)
            MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
        else
            break;
    }
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void applyColorFilterToMenuIcon(final Menu menu, final int color, final int popupColor,
        final int highlightColor, final Mode mode, final int... excludedGroups) {
    for (int i = 0, j = menu.size(); i < j; i++) {
        final MenuItem item = menu.getItem(i);
        final Drawable icon = item.getIcon();
        final ContextMenuInfo info = item.getMenuInfo();
        if (icon != null && !ArrayUtils.contains(excludedGroups, item.getGroupId())) {
            icon.mutate();//from  w  w w  .j av  a 2 s .  c o  m
            if (info instanceof TwidereMenuInfo) {
                final TwidereMenuInfo sInfo = (TwidereMenuInfo) info;
                icon.setColorFilter(sInfo.isHighlight() ? sInfo.getHighlightColor(highlightColor) : color,
                        mode);
            } else {
                icon.setColorFilter(color, mode);
            }
        }
        if (item.hasSubMenu()) {
            // SubMenu item is always in popup
            applyColorFilterToMenuIcon(item.getSubMenu(), popupColor, popupColor, highlightColor, mode,
                    excludedGroups);
        }
    }
}

From source file:io.github.hidroh.materialistic.MenuTintDelegate.java

@SuppressWarnings("unused")
public void setIcon(MenuItem item, @DrawableRes int icon) {
    item.setIcon(icon);// w ww  .  j a v a 2s .  co  m
    Drawable drawable = item.getIcon();
    drawable = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawable, mTextColorPrimary);
}