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:gov.wa.wsdot.android.wsdot.ui.camera.CameraImageFragment.java

private void toggleStar(MenuItem item) {
    Snackbar added_snackbar = Snackbar.make(getView(), R.string.add_favorite, Snackbar.LENGTH_SHORT);

    Snackbar removed_snackbar = Snackbar.make(getView(), R.string.remove_favorite, Snackbar.LENGTH_SHORT);

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        item.setTitle("Favorite checkbox, not checked");
        viewModel.setIsStarredFor(mId, 0);
        removed_snackbar.show();/*  ww w .  java2 s. c o  m*/
        mIsStarred = false;
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        item.setTitle("Favorite checkbox, checked");
        viewModel.setIsStarredFor(mId, 1);
        added_snackbar.show();
        mIsStarred = true;
    }
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();/*from  w w w.j a va 2s  .c  o  m*/
    MenuItem mi = menu.add(Menu.NONE, R.id.menu_account_delete, Menu.FIRST + 10, R.string.delete);
    mi.setIcon(R.drawable.ic_clear_grey);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    if (SessionManager.getInstance(getActivity()).hasSession(account.getId())) {
        mi = menu.add(Menu.NONE, R.id.my_profile, Menu.FIRST, R.string.my_profile);
        mi.setIcon(R.drawable.ic_account_circle_grey);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }
}

From source file:org.freespanish.diccionario.fragments.search.SearchFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    if (item.getItemId() == R.id.action_fav) {
        Definition definition = this.searchPresenter.notifyDefinitionToRetrieve("word = ?", this.currentWord,
                getActivity());//from w w  w  . j  a  va  2  s .c  o m

        if (definition != null) {
            definition.isFavorite = !definition.isFavorite;
            item.setIcon(definition.isFavorite ? R.drawable.ic_favorite_white_24dp
                    : R.drawable.ic_favorite_border_white_24dp);
            item.setTitle(definition.isFavorite ? getString(R.string.add_fav_text)
                    : getString(R.string.remove_fav_text));
            this.searchPresenter.notifyDefinitionToStore(definition, getActivity());
        }

    }

    return super.onOptionsItemSelected(item);
}

From source file:th.in.ffc.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem whatnew = menu.add(Menu.NONE, R.layout.whatnew_dialog, Menu.NONE, "what new");
    whatnew.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    SharedPreferences sp = getSharedPreferences(FamilyFolderCollector.TAG, MODE_PRIVATE);
    int prev = sp.getInt(FamilyFolderCollector.PREF_VERSION, 0);
    int now = getResources().getInteger(R.integer.version_code);
    whatnew.setIcon((now > prev) ? R.drawable.ic_action_star : R.drawable.ic_action_start_dark);

    return super.onCreateOptionsMenu(menu);

}

From source file:org.mariotaku.twidere.fragment.UserListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    final ParcelableUserList userList = mUserList;
    MenuUtils.setMenuItemAvailability(menu, R.id.info, userList != null);
    menu.removeGroup(MENU_GROUP_USER_LIST_EXTENSION);
    if (userList != null) {
        final boolean isMyList = userList.user_key.equals(userList.account_key);
        final boolean isFollowing = userList.is_following;
        MenuUtils.setMenuItemAvailability(menu, R.id.edit, isMyList);
        MenuUtils.setMenuItemAvailability(menu, R.id.follow, !isMyList);
        MenuUtils.setMenuItemAvailability(menu, R.id.add, isMyList);
        MenuUtils.setMenuItemAvailability(menu, R.id.delete, isMyList);
        final MenuItem followItem = menu.findItem(R.id.follow);
        if (isFollowing) {
            followItem.setIcon(R.drawable.ic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {//from   w w  w .  j  a va  2s .  c o  m
            followItem.setIcon(R.drawable.ic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
        final Intent extensionsIntent = new Intent(INTENT_ACTION_EXTENSION_OPEN_USER_LIST);
        extensionsIntent.setExtrasClassLoader(getActivity().getClassLoader());
        extensionsIntent.putExtra(EXTRA_USER_LIST, userList);
        MenuUtils.addIntentToMenu(getActivity(), menu, extensionsIntent, MENU_GROUP_USER_LIST_EXTENSION);
    } else {
        MenuUtils.setMenuItemAvailability(menu, R.id.edit, false);
        MenuUtils.setMenuItemAvailability(menu, R.id.follow, false);
        MenuUtils.setMenuItemAvailability(menu, R.id.add, false);
        MenuUtils.setMenuItemAvailability(menu, R.id.delete, false);
    }
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.menu_wallpaper_search_sort, menu);
    MenuItem search = menu.findItem(R.id.menu_search);
    MenuItem sort = menu.findItem(R.id.menu_sort);

    int color = ColorHelper.getAttributeColor(getActivity(), R.attr.toolbar_icon);
    search.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_search, color));
    sort.setIcon(DrawableHelper.getTintedDrawable(getActivity(), R.drawable.ic_toolbar_sort, color));

    mSearchView = (SearchView) search.getActionView();
    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);

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

    mSearchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

        @Override/*w w w .j a v  a2  s  .  co m*/
        public boolean onQueryTextChange(String string) {
            filterSearch(string);
            return true;
        }

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

From source file:com.money.manager.ex.recurring.transactions.RecurringTransactionListFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    //        MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_item_calendar, menu);
    MenuItem calendar = menu.findItem(R.id.menuCalendar);
    if (calendar != null) {
        Drawable icon = new UIHelper(getActivity()).getIcon(MMXIconFont.Icon.mmx_calendar);
        calendar.setIcon(icon);
    }//from  w  w w.jav  a  2s.  co m
}

From source file:com.example.android.supportv7.app.ActionBarMechanics.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Menu items default to never show in the action bar. On most devices this means
    // they will show in the standard options menu panel when the menu button is pressed.
    // On xlarge-screen devices a "More" button will appear in the far right of the
    // Action Bar that will display remaining items in a cascading menu.
    menu.add("Normal item");

    MenuItem actionItem = menu.add("Action Button");

    // Items that show as actions should favor the "if room" setting, which will
    // prevent too many buttons from crowding the bar. Extra items will show in the
    // overflow area.
    MenuItemCompat.setShowAsAction(actionItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);

    // Items that show as actions are strongly encouraged to use an icon.
    // These icons are shown without a text description, and therefore should
    // be sufficiently descriptive on their own.
    actionItem.setIcon(android.R.drawable.ic_menu_share);
    return true;//from   w  w w  .  j a  v a  2 s.  com
}

From source file:com.money.manager.ex.assetallocation.AssetAllocationActivity.java

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

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

    // customize icons

    // Currencies
    MenuItem currenciesMenu = menu.findItem(R.id.menu_currencies);
    if (currenciesMenu != null) {
        FontIconDrawable icon = FontIconDrawable.inflate(this, R.xml.ic_euro);
        UIHelper uiHelper = new UIHelper(this);
        icon.setTextColor(uiHelper.getColor(R.attr.toolbarItemColor));
        currenciesMenu.setIcon(icon);
    }/*from  w  w  w . ja v a2s  . com*/

    //        // Overview
    //        MenuItem overview = menu.findItem(R.id.menu_asset_allocation_overview);
    //        FontIconDrawable icon = FontIconDrawable.inflate(this, R.xml.ic_report_page);
    //        icon.setTextColor(UIHelper.getColor(this, R.attr.toolbarItemColor));
    //        overview.setIcon(icon);

    // New Asset Allocation view
    MenuItem newForm = menu.findItem(R.id.menu_new_asset_allocation);
    FontIconDrawable icon = FontIconDrawable.inflate(this, R.xml.ic_pie_chart);
    UIHelper uiHelper = new UIHelper(this);
    icon.setTextColor(uiHelper.getColor(R.attr.toolbarItemColor));
    newForm.setIcon(icon);

    return true;
}

From source file:com.money.manager.ex.reports.CategoriesReportFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    // pie chart//from  w  w  w . j av a2s  .c o  m
    MenuItem itemChart = menu.findItem(R.id.menu_chart);
    if (itemChart != null) {
        itemChart.setVisible(!(((CategoriesReportActivity) getActivity()).mIsDualPanel));
        UIHelper uiHelper = new UIHelper(getActivity());
        itemChart.setIcon(uiHelper.resolveAttribute(R.attr.ic_action_pie_chart));
    }
}