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.glanznig.beepme.view.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    BeeperApp app = (BeeperApp) getApplication();

    // hide/show test beep menu entry
    MenuItem testBeep = menu.findItem(R.id.action_test_beep);
    if (app.getPreferences().isTestMode() && app.isBeeperActive()) {
        testBeep.setVisible(true);/*from  ww w.  j  a v  a 2 s. c o  m*/
    } else {
        testBeep.setVisible(false);
    }

    // update toggle beeper icon
    MenuItem item = menu.findItem(R.id.action_toggle_beeper);
    if (app.isBeeperActive()) {
        item.setIcon(R.drawable.ic_menu_beeper_on);
    } else {
        item.setIcon(R.drawable.ic_menu_beeper_off);
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.dm.wallpaper.board.fragments.WallpaperSearchFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_wallpaper_search, menu);
    MenuItem search = menu.findItem(R.id.menu_search);
    int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
    search.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color));

    mSearchView = (SearchView) MenuItemCompat.getActionView(search);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_EXTRACT_UI | EditorInfo.IME_ACTION_SEARCH);
    mSearchView.setQueryHint(getActivity().getResources().getString(R.string.menu_search));
    mSearchView.setMaxWidth(Integer.MAX_VALUE);

    MenuItemCompat.expandActionView(search);
    mSearchView.setIconifiedByDefault(false);
    mSearchView.clearFocus();//  w w  w. j a va  2 s .c  o m

    ViewHelper.setSearchViewTextColor(mSearchView, color);
    ViewHelper.setSearchViewBackgroundColor(mSearchView, Color.TRANSPARENT);
    ViewHelper.setSearchViewCloseIcon(mSearchView, R.drawable.ic_toolbar_close);
    ViewHelper.setSearchViewSearchIcon(mSearchView, null);

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override
        public boolean onQueryTextChange(String string) {
            filterSearch(string);
            return true;
        }

        @Override
        public boolean onQueryTextSubmit(String string) {
            mSearchView.clearFocus();
            return true;
        }
    });
}

From source file:de.tap.easy_xkcd.fragments.FavoritesFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.findItem(R.id.action_latest).setVisible(false);
    menu.findItem(R.id.action_search).setVisible(false);
    menu.findItem(R.id.action_boomark).setVisible(false);
    menu.findItem(R.id.action_overview).setVisible(false);
    menu.findItem(R.id.delete_favorites).setVisible(true);
    MenuItem fav = menu.findItem(R.id.action_favorite);
    fav.setIcon(R.drawable.ic_action_favorite);
    fav.setTitle(R.string.action_favorite_remove);
    //If the FAB is visible, hide the random comic menu item
    if (((MainActivity) getActivity()).getFab().getVisibility() == View.GONE) {
        menu.findItem(R.id.action_random).setVisible(true);
    } else {/* w  ww.  j  a v a 2  s. c o  m*/
        menu.findItem(R.id.action_random).setVisible(false);
    }
}

From source file:com.julia.android.stockhawk.ui.MainActivity.java

private void setDisplayModeMenuItemIcon(MenuItem item) {
    if (PrefUtils.getDisplayMode(this).equals(getString(R.string.pref_display_mode_absolute_key))) {
        item.setIcon(R.drawable.ic_percentage);
    } else {/*w w  w . jav  a 2 s. com*/
        item.setIcon(R.drawable.ic_dollar);
    }
}

From source file:com.mifos.mifosxdroid.online.loancharge.LoanChargeFragment.java

@SuppressWarnings("deprecation")
@Override/*from w w  w  .  j  ava 2s. co  m*/
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    MenuItem menuItemAddNewLoanCharge = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_LOAN_CHARGES, Menu.NONE,
            getString(R.string.add_new));
    menuItemAddNewLoanCharge.setIcon(getResources().getDrawable(R.drawable.ic_add_white_24dp));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        menuItemAddNewLoanCharge.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    super.onPrepareOptionsMenu(menu);
}

From source file:task.application.com.colette.navigation.AppNavigationViewAsDrawerImpl.java

private void createNavDrawerItems(NavigationModel.NavigationItemEnum[] items) {
    if (mNavigationView != null) {
        Menu menu = mNavigationView.getMenu();
        for (int i = 0; i < items.length; i++) {
            MenuItem item = menu.findItem(items[i].getId());
            if (item != null) {
                item.setVisible(true);/*from ww  w. jav  a  2s .  c o m*/
                item.setIcon(items[i].getIcon());
                item.setTitle(items[i].getTitleResource());
            } else {
                LogUtils.LOGE(TAG,
                        "Menu Item for navigation item with title " + (items[i].getTitleResource() != 0
                                ? mActivity.getResources().getString(items[i].getTitleResource())
                                : "") + "not found");
            }
        }

        for (int i = 0; i < menu.size(); i++) {
            MenuItem mi = menu.getItem(i);
            applyFontToSubMenu(mi);
            applyFontToMenuItem(mi);
        }

        mNavigationView.setNavigationItemSelectedListener(this);
    }
}

From source file:fr.simon.marquis.preferencesmanager.ui.PreferencesActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean fav = Utils.isFavorite(packageName, this);
    MenuItem itemFav = menu.findItem(R.id.action_fav);
    if (itemFav != null) {
        itemFav.setIcon(fav ? R.drawable.ic_action_star_10 : R.drawable.ic_action_star_0)
                .setTitle(fav ? R.string.action_unfav : R.string.action_fav);
    }//from  ww w. j a v a  2  s .  c om
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.facebook.getrecommendations.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.main_activity_actions, menu);
    MenuItem menuItem = menu.findItem(R.id.menu_overflow);
    Drawable drawable = getResources().getDrawable(R.drawable.fbui_3_dots_v_l);
    int color = getResources().getColor(R.color.getrecommendations_primary_light);
    drawable.setColorFilter(color, PorterDuff.Mode.SRC_IN);
    menuItem.setIcon(drawable);
    return super.onCreateOptionsMenu(menu);
}

From source file:com.mifos.mifosxdroid.online.clientcharge.ClientChargeFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();//from   ww  w.j a  v a2s .c o  m
    MenuItem menuItemAddNewDocument = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_CHARGES, Menu.NONE,
            getString(R.string.add_new));
    menuItemAddNewDocument
            .setIcon(ResourcesCompat.getDrawable(getResources(), R.drawable.ic_add_white_24dp, null));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        menuItemAddNewDocument.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    super.onPrepareOptionsMenu(menu);
}

From source file:br.com.viniciuscr.notification2android.mediaPlayer.MusicUtils.java

public static void setPartyShuffleMenuIcon(Menu menu) {
    MenuItem item = menu.findItem(Defs.PARTY_SHUFFLE);
    if (item != null) {
        int shuffle = MusicUtils.getCurrentShuffleMode();
        if (shuffle == MediaPlaybackService.SHUFFLE_AUTO) {
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle_off);
        } else {/*from   w ww .java  2 s.  c  o m*/
            item.setIcon(R.drawable.ic_menu_party_shuffle);
            item.setTitle(R.string.party_shuffle);
        }
    }
}