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.gnufabio.costituzione.DetailedActivity.java

public void updateFavoriteButton(MenuItem favorite) {
    boolean isFav = mEntry.isFavourite();

    int icon = isFav ? R.drawable.is_favorite_light : R.drawable.is_not_favorite_light;
    int title = isFav ? R.string.remove_from_fav : R.string.add_to_fav;

    favorite.setIcon(icon).setTitle(title);
}

From source file:de.stadtrallye.rallyesoft.ConnectionAssistantActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem scan_qr = menu.add(Menu.NONE, R.id.scan_qr_login, 10, R.string.scan_barcode);
    scan_qr.setIcon(R.drawable.ic_scan_qr_light);
    scan_qr.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;/*from   ww w . j a va  2 s  . c o  m*/
}

From source file:de.lebenshilfe_muenster.uk_gebaerden_muensterland.sign_browser.SignBrowserFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    Log.d(TAG, "onOptionsItemSelected " + hashCode());
    if (item.getItemId() == R.id.action_toggle_starred) {
        if (!this.showStarredOnly) {
            this.showStarredOnly = true;
            item.setIcon(R.drawable.ic_sign_browser_grade_checked);
        } else {/*  ww w.  j a  va 2 s  .co  m*/
            this.showStarredOnly = false;
            item.setIcon(R.drawable.ic_sign_browser_grade_no_stroke);
        }
        this.loadSignsTask = new LoadSignsTask(getActivity());
        this.loadSignsTask.execute(this.showStarredOnly);
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.twolinessoftware.activities.BaseNavigationActivity.java

private void setMenuItemIcon(Menu menu, @IdRes int menuResourceId, Icon iconName, boolean checked) {

    MenuItem item = menu.findItem(menuResourceId);
    Timber.v("setup menu item icon: " + item + ", checked: " + checked);
    item.setChecked(checked);//  w w  w  .  jav a 2  s.  com

    int primaryColor = ThemeUtil.getPrimaryColor(this);
    int accentColor = ThemeUtil.getAccentColor(this);

    item.setIcon(new IconDrawable(BaseNavigationActivity.this, iconName)
            .color(checked ? primaryColor : accentColor));
}

From source file:org.dmfs.webcal.fragments.CalendarTitleFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();
    if (id == R.id.menu_starred) {
        boolean checked = !item.isChecked();
        item.setChecked(checked);/*w  w w  .ja  v  a  2 s .c o  m*/
        // Selectors don't seem to work with menu options, so we have to hard code the icons.
        item.setIcon(checked ? R.drawable.ic_fa_star : R.drawable.ic_fa_star_o);
        ContentItem.setStarred(getActivity(), mId, checked);
        Analytics.event("starred", "calendar-action", checked ? "starred" : "un-starred", null,
                String.valueOf(mId), null);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.dreier.mytargets.features.statistics.StatisticsActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    super.onPrepareOptionsMenu(menu);
    final MenuItem filter = menu.findItem(R.id.action_filter);
    final MenuItem export = menu.findItem(R.id.action_export);
    filter.setIcon(showFilter ? R.drawable.ic_clear_filter_white_24dp : R.drawable.ic_filter_white_24dp);
    // only show filter if we have at least one category to filter by
    boolean filterAvailable = binding.distanceTags.getTags().size() > 1
            || binding.diameterTags.getTags().size() > 1 || binding.bowTags.getTags().size() > 1
            || binding.arrowTags.getTags().size() > 1;
    filter.setVisible(rounds != null && filterAvailable);
    export.setVisible(rounds != null);//from   w ww .j  av  a 2s .  c  o m
    return true;
}

From source file:com.orpheusdroid.screenrecorder.VideosListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem refresh = menu.add("Refresh");
    refresh.setIcon(R.drawable.ic_refresh_white_24dp);
    refresh.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
    refresh.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override/*from www  .  j  av  a2  s  .c o  m*/
        public boolean onMenuItemClick(MenuItem menuItem) {
            // Prevent repeated refresh requests
            if (swipeRefreshLayout.isRefreshing())
                return false;
            videosList.clear();
            checkPermission();
            Log.d(Const.TAG, "Refreshing");
            return false;
        }
    });
}

From source file:com.artemchep.horario.ui.fragments.details.DetailsHelper.java

void setAppBarBackgroundColor(@ColorInt int color) {
    color |= 0xFF000000; // ignore alpha bits
    final boolean isColorDark = ColorUtil.isColorDark(color);

    Drawable overflowIcon;/*from   ww  w. j a va2 s.com*/
    if (isColorDark) {
        mCollapsingToolbar.setExpandedTitleColor(Color.WHITE);
        mCollapsingToolbar.setCollapsedTitleTextColor(Color.WHITE);
        overflowIcon = ContextCompat.getDrawable(mActivity, R.drawable.ic_dots_vertical_white_24dp);
        if (mSmartTabLayout != null) {
            mSmartTabLayout.setDefaultTabTextColor(Color.WHITE);
            mSmartTabLayout.setSelectedIndicatorColors(Color.WHITE);
        }
    } else {
        mCollapsingToolbar.setExpandedTitleColor(Color.BLACK);
        mCollapsingToolbar.setCollapsedTitleTextColor(Color.BLACK);
        overflowIcon = ContextCompat.getDrawable(mActivity, R.drawable.ic_dots_vertical_black_24dp);
        if (mSmartTabLayout != null) {
            mSmartTabLayout.setDefaultTabTextColor(Color.BLACK);
            mSmartTabLayout.setSelectedIndicatorColors(Color.BLACK);
        }
    }

    mCollapsingToolbar.setContentScrimColor(color);
    if (mBackdropToolbar != null) {
        mBackdropToolbar.setBackgroundColor(color);
    } else
        mAppBar.setBackgroundColor(color);
    mToolbar.setOverflowIcon(overflowIcon);

    if (mActivity.mContainers.hasSingleColumn()) {
        int iconRes;
        if (mActivity.mAppBar.hasGeneralToolbar()) {
            iconRes = isColorDark ? R.drawable.ic_close_white_24dp : R.drawable.ic_close_black_24dp;
        } else
            iconRes = isColorDark ? R.drawable.ic_backburger_white_24dp : R.drawable.ic_backburger_black_24dp;
        Drawable navIcon = ContextCompat.getDrawable(mActivity, iconRes);
        mToolbar.setNavigationIcon(navIcon);
    }

    MenuItem editItem = mToolbar.getMenu().findItem(R.id.action_edit);
    if (editItem != null) {
        Drawable editIcon = isColorDark ? ContextCompat.getDrawable(mActivity, R.drawable.ic_pencil_white_24dp)
                : ContextCompat.getDrawable(mActivity, R.drawable.ic_pencil_black_24dp);
        editItem.setIcon(editIcon);
    }

    MenuItem shareItem = mToolbar.getMenu().findItem(R.id.action_share);
    if (shareItem != null) {
        Drawable shareIcon = isColorDark
                ? ContextCompat.getDrawable(mActivity, R.drawable.ic_share_variant_white_24dp)
                : ContextCompat.getDrawable(mActivity, R.drawable.ic_share_variant_black_24dp);
        shareItem.setIcon(shareIcon);
    }
}

From source file:com.money.manager.ex.assetallocation.editor.AssetAllocationEditorActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);

    getMenuInflater().inflate(R.menu.menu_asset_allocation_editor, menu);

    // customize icons

    UIHelper ui = new UIHelper(this);

    // Currencies
    MenuItem currenciesMenu = menu.findItem(R.id.menu_currencies);
    if (currenciesMenu != null) {
        IconicsDrawable icon = ui.getIcon(GoogleMaterial.Icon.gmd_euro_symbol);
        currenciesMenu.setIcon(icon);
    }/*ww w  .  j  av  a  2s  . com*/

    return true;
}

From source file:com.loloof64.android.chess_position_manager.MainActivity.java

private void setSelectionMode(boolean selectionMode) {
    this.selectionMode = selectionMode;
    if (listAdapter != null)
        listAdapter.setSelectionMode(selectionMode);
    if (menu != null) {
        MenuItem toggleSelectionItem = menu.findItem(R.id.action_toggle_selection_mode);
        toggleSelectionItem.setIcon(
                selectionMode ? R.drawable.ic_action_action_navigate : R.drawable.ic_action_action_list);
        toggleSelectionItem.setTitle(selectionMode ? R.string.action_toggle_in_navigation_mode
                : R.string.action_toggle_in_list_mode);
    }//w w  w . ja va  2  s  .  c o m
}