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:com.arantius.tivocommander.Utils.java

@SuppressLint("NewApi")
final static void addToMenu(Menu menu, Activity activity, int itemId, int iconId, String title,
        int showAsAction) {
    if (Utils.activityForMenuId(itemId) == activity.getClass()) {
        return;/*w  ww .  j  a  v  a  2s  .  c  o  m*/
    }
    MenuItem menuitem = menu.add(Menu.NONE, itemId, Menu.NONE, title);
    menuitem.setIcon(iconId);
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        menuitem.setShowAsAction(showAsAction);
    }
}

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);
}

From source file:com.github.michalbednarski.intentslab.Utils.java

public static void updateLegacyCheckedIcon(MenuItem menuItem) {
    if (Build.VERSION.SDK_INT < Build.VERSION_CODES.HONEYCOMB) {
        menuItem.setIcon(menuItem.isChecked() ? R.drawable.ic_menu_checked : R.drawable.ic_menu_unchecked);
    }//  w w  w .  java  2  s . c o m
}

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.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 a 2  s .  c  o m
        if (icon != null) {
            icon.mutate().setColorFilter(color, PorterDuff.Mode.SRC_IN);
            item.setIcon(icon);
        }
    }
}

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

static public void setFavState(Context context, MenuItem item, boolean is_fav, boolean is_toolbar) {
    if (is_fav) {
        item.setTitle(R.string.action_unfav_trip);
        item.setIcon(is_toolbar ? getToolbarDrawable(context, R.drawable.ic_action_star)
                : getTintedDrawable(context, R.drawable.ic_action_star));
    } else {//from w  w w  .  j  a  va2  s .c o  m
        item.setTitle(R.string.action_fav_trip);
        item.setIcon(is_toolbar ? getToolbarDrawable(context, R.drawable.ic_action_star_empty)
                : getTintedDrawable(context, R.drawable.ic_action_star_empty));
    }
}

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

public static void getMenu(Menu menu) {
    MenuItem mi = menu.add(Menu.NONE, MenuActionItem.MENU_PROFILE, Menu.FIRST + MenuActionItem.MENU_PROFILE,
            R.string.my_profile);/*w w  w. j a  va2 s.  c om*/
    mi.setIcon(R.drawable.ic_avatar);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

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

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

From source file:com.example.android.actionbarcompat.basic.MainActivity.java

/**
 * Use this method to instantiate your menu, and add your items to it. You
 * should return true if you have added items to it and want the menu to be displayed.
 *//*  ww w.j  ava2 s . c  om*/
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate our menu from the resources by using the menu inflater.
    getMenuInflater().inflate(R.menu.main, menu);

    // It is also possible add items here. Use a generated id from
    // resources (ids.xml) to ensure that all menu ids are distinct.
    MenuItem locationItem = menu.add(0, R.id.menu_location, 0, R.string.menu_location);
    locationItem.setIcon(R.drawable.ic_action_location);

    // Need to use MenuItemCompat methods to call any action item related methods
    MenuItemCompat.setShowAsAction(locationItem, MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;
}

From source file:com.example.ward.view.CursorFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    // Place an action bar item for searching.
    MenuItem item = menu.add("Search");
    item.setIcon(android.R.drawable.ic_menu_search);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    SearchView sv = new SearchView(getActivity());
    sv.setOnQueryTextListener(this);
    item.setActionView(sv);//from  ww w.  j  av a 2  s .co m
}