Example usage for android.view MenuItem setIcon

List of usage examples for android.view MenuItem setIcon

Introduction

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

Prototype

public MenuItem setIcon(@DrawableRes int iconRes);

Source Link

Document

Change the icon associated with this item.

Usage

From source file:Main.java

public static void setMenuItemEnabled(final Menu menu, final boolean enabled, final int viewId,
        final int enabledResId, final int disabledResId) {
    final MenuItem v = menu.findItem(viewId);
    if (v != null) {
        v.setIcon(enabled ? enabledResId : disabledResId);
        v.setEnabled(enabled);/*from  w ww. ja v  a  2 s . c  o  m*/
    }
}

From source file:Main.java

public static void setMenuItemChecked(final Menu menu, final boolean checked, final int viewId,
        final int checkedResId, final int uncheckedResId) {
    final MenuItem v = menu.findItem(viewId);
    if (v != null) {
        v.setChecked(checked);//from w ww. ja  v a2  s  . c om
        v.setIcon(checked ? checkedResId : uncheckedResId);
    }
}

From source file:org.alfresco.mobile.android.application.fragments.MenuFragmentHelper.java

public static MenuItem getMenu(Context context, Menu menu) {
    if (menu == null || context == null) {
        return null;
    }//  w  ww.  jav a2s .  co  m
    if (AccessibilityUtils.isEnabled(context)) {
        MenuItem mi = menu.add(Menu.NONE, R.id.menu_refresh, Menu.FIRST + 40, R.string.refresh);
        mi.setIcon(R.drawable.ic_refresh);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
        return mi;
    } else {
        return null;
    }
}

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

public static void tintSaveIcon(MenuItem item, Context context, int color) {
    item.setIcon(ColorUtils.getTintedIcon(context, R.drawable.ic_save, color));
}

From source file:com.fjoglar.etsitnoticias.utils.UiUtils.java

/**
 * Update the menu's bookmark icon in function of its status.
 *
 * @param menu          Menu container of MenuItem.
 * @param isBookmarked  Status of bookmark.
 * @param context       The context of activity.
 *///from   ww w  . j a v a2 s .  c om
public static void updateBookmarkIcon(Menu menu, boolean isBookmarked, Context context) {
    if (menu != null) {
        MenuItem menuItem = menu.findItem(R.id.action_bookmark);
        if (isBookmarked) {
            menuItem.setIcon(context.getResources().getDrawable(R.drawable.ic_bookmark));
        } else {
            menuItem.setIcon(context.getResources().getDrawable(R.drawable.ic_bookmark_border));
        }
    }
}

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 source file:org.openremote.android.console.Main.java

public static void populateMenu(Menu menu) {
    menu.setQwertyMode(true);/*from   w w  w  . jav a 2  s.  com*/
    MenuItem configItem = menu.add(0, Constants.MENU_ITEM_SETTING, 0, R.string.configure);
    configItem.setIcon(R.drawable.ic_menu_manage);
    MenuItem quit = menu.add(0, Constants.MENU_ITEM_QUIT, 0, R.string.quit);
    quit.setIcon(R.drawable.ic_menu_close_clear_cancel);
}

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

/**
 * This code was created by Aidan Follestad. Complete credits to him.
 *///from  www . j av  a2 s . co m
@SuppressWarnings("PrivateResource")
public static void tintSearchView(Context context, @NonNull Toolbar toolbar, MenuItem item,
        @NonNull SearchView searchView, @ColorInt int color) {
    item.setIcon(ColorUtils.getTintedIcon(context, R.drawable.ic_search, color));
    final Class<?> searchViewClass = searchView.getClass();
    try {
        final Field mCollapseIconField = toolbar.getClass().getDeclaredField("mCollapseIcon");
        mCollapseIconField.setAccessible(true);
        final Drawable drawable = (Drawable) mCollapseIconField.get(toolbar);
        if (drawable != null)
            mCollapseIconField.set(toolbar, ColorUtils.getTintedIcon(drawable, color));

        final Field mSearchSrcTextViewField = searchViewClass.getDeclaredField("mSearchSrcTextView");
        mSearchSrcTextViewField.setAccessible(true);
        final EditText mSearchSrcTextView = (EditText) mSearchSrcTextViewField.get(searchView);
        mSearchSrcTextView.setTextColor(color);
        mSearchSrcTextView.setHintTextColor(ColorUtils.adjustAlpha(color, 0.5f));
        setCursorTint(mSearchSrcTextView, color);

        hideSearchHintIcon(context, searchView);

        Field field = searchViewClass.getDeclaredField("mSearchButton");
        tintImageView(searchView, field, color);
        field = searchViewClass.getDeclaredField("mGoButton");
        tintImageView(searchView, field, color);
        field = searchViewClass.getDeclaredField("mCloseButton");
        tintImageView(searchView, field, color);
        field = searchViewClass.getDeclaredField("mVoiceButton");
        tintImageView(searchView, field, color);
        field = searchViewClass.getDeclaredField("mCollapsedIcon");
        tintImageView(searchView, field, color);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:org.alfresco.mobile.android.application.fragments.workflow.process.ProcessesFragment.java

public static void getMenu(Context context, Menu menu) {
    MenuItem mi;

    mi = menu.add(Menu.NONE, R.id.menu_workflow_add, Menu.FIRST, R.string.workflow_start);
    mi.setIcon(android.R.drawable.ic_menu_add);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    MenuFragmentHelper.getMenu(context, menu);
}

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);
        }//  w  ww  . j  a  v a2 s .c o m
    }
}