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:de.tap.easy_xkcd.fragments.overview.OverviewListFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_boomark:
        super.goToComic(bookmark - 1);
        break;//  ww  w.j  a  v  a 2 s  .c o  m
    case R.id.action_unread:
        databaseManager.setComicsUnread();
        setupAdapter();
        break;
    case R.id.action_favorite:
        if (prefHelper.overviewFav()) {
            item.setIcon(R.drawable.ic_favorite_outline);
            item.setTitle(R.string.nv_favorites);
        } else {
            item.setIcon(R.drawable.ic_action_favorite);
            item.setTitle(R.string.action_overview);
        }
        prefHelper.setOverviewFav(!prefHelper.overviewFav());
        getActivity().invalidateOptionsMenu();
        setupAdapter();
        break;
    case R.id.action_hide_read:
        item.setChecked(!item.isChecked());
        prefHelper.setHideRead(item.isChecked());
        setupAdapter();
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.esri.android.mapsapp.tools.MeasuringTool.java

@Override
public boolean onCreateActionMode(ActionMode mode, Menu menu) {
    mMode = mode;/*from w  w  w . j  a va2  s. co m*/
    init();
    MenuItem item;
    item = menu.add(Menu.NONE, MENU_UNDO, 1, "undo");
    item.setIcon(android.R.drawable.ic_menu_revert);
    item.setVisible(false);

    item = menu.add(Menu.NONE, MENU_DELETE, 2, "clear");
    item.setIcon(android.R.drawable.ic_menu_delete);
    item.setVisible(false);

    item = menu.add(Menu.NONE, MENU_PREF, 3, "preferences");
    item.setIcon(android.R.drawable.ic_menu_manage);
    item.setActionProvider(new Preferences(mContext));
    return true;
}

From source file:com.osama.cryptofm.filemanager.ui.FilemanagerTabs.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    Log.d(TAG, "onPrepareOptionsMenu: preparing menu");
    if (SharedData.IS_IN_COPY_MODE) {
        return super.onPrepareOptionsMenu(menu);
    }//w  ww .ja va  2s. c  o  m
    MenuItem item = menu.getItem(0);
    if (!getPreferences(Context.MODE_PRIVATE).getBoolean("layout", true)) {
        item.setIcon(getDrawable(R.drawable.ic_grid_view));
    }
    return true;
}

From source file:com.alibaba.weex.extend.module.WXTitleBar.java

@JSMethod
public void setStyle(JSONObject object) {
    String bgColor = object.getString("backgroundColor");
    String color = object.getString("foregroundColor");
    ActionBar actionBar = getActionBar();
    if (actionBar != null) {
        if (bgColor != null) {
            int c = WXResourceUtils.getColor(bgColor);
            actionBar.setBackgroundDrawable(new ColorDrawable(c));
        }/*  w  ww  .j  av  a  2 s.  c  o  m*/

        if (color != null) {
            int c = WXResourceUtils.getColor(color);

            Toolbar toolbar = (Toolbar) ((Activity) mWXSDKInstance.getContext()).findViewById(R.id.toolbar);
            if (toolbar != null) {
                toolbar.setTitleTextColor(c);
                toolbar.setSubtitleTextColor(c);

                Drawable upNavigation = toolbar.getNavigationIcon();
                if (null != upNavigation) {
                    upNavigation = DrawableCompat.wrap(upNavigation);
                    upNavigation = upNavigation.mutate();
                    DrawableCompat.setTint(upNavigation, c);
                    toolbar.setNavigationIcon(upNavigation);
                }

                Drawable overflowIcon = toolbar.getOverflowIcon();
                if (null != overflowIcon) {
                    overflowIcon = DrawableCompat.wrap(overflowIcon);
                    overflowIcon = overflowIcon.mutate();
                    DrawableCompat.setTint(overflowIcon, c);
                    toolbar.setOverflowIcon(overflowIcon);
                }

                Menu menu = toolbar.getMenu();
                if (menu != null && menu.size() > 0) {
                    for (int i = 0; i < menu.size(); i++) {
                        MenuItem item = menu.getItem(i);
                        if (item != null && item.getIcon() != null) {
                            Drawable drawable = item.getIcon();
                            if (null != drawable) {
                                drawable = DrawableCompat.wrap(drawable);
                                drawable = drawable.mutate();
                                DrawableCompat.setTint(drawable, c);
                                item.setIcon(drawable);
                            }
                        }
                    }
                    ((Activity) mWXSDKInstance.getContext()).invalidateOptionsMenu();
                }
            }
        }
    }
}

From source file:kr.ac.knu.odego.activity.MainActivity.java

/**
 *   Override//w  w  w.  j a  v  a 2 s . c  o m
 */
@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);
    MenuItem btMenuItem = menu.findItem(R.id.action_bluetooth);

    if (mBtAdapter != null) {
        if (mBtAdapter.isEnabled())
            btMenuItem.setIcon(R.drawable.bt_on);
        else
            btMenuItem.setIcon(R.drawable.bt_off);
    }

    return true;
}

From source file:com.murati.oszk.audiobook.ui.MusicPlayerActivity.java

public void updateBookButtons(String mediaId) {
    if (mMenu == null)
        return;//from  ww w .  j  a  v a  2  s.  co m

    boolean isValidBook = (mediaId != null && mediaId.startsWith(MediaIDHelper.MEDIA_ID_BY_EBOOK + "/"));

    // Set Favorite Menu visibility
    MenuItem mFavorite = null;
    try {
        mFavorite = mMenu.findItem(R.id.option_favorite);
        mFavorite.setVisible(isValidBook);

        // Set Favorite icon
        if (isValidBook && FavoritesHelper.isFavorite(mediaId))
            mFavorite.setIcon(R.drawable.ic_star_on);
        else
            mFavorite.setIcon(R.drawable.ic_star_off);

    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }

    // Set Download/Delete menu visibility based on offline status
    boolean isOfflineBook = false;
    if (isValidBook) {
        try {
            isOfflineBook = OfflineBookService.isOfflineBook(mediaId);
        } catch (Exception e) {
            Log.d(TAG, e.getMessage());
        }
    }

    MenuItem mDownload = null;
    MenuItem mDelete = null;
    try {
        mDownload = mMenu.findItem(R.id.option_download);
        mDownload.setVisible(isValidBook && !isOfflineBook);

        mDelete = mMenu.findItem(R.id.option_delete);
        mDelete.setVisible(isValidBook && isOfflineBook);
    } catch (Exception e) {
        Log.d(TAG, e.getMessage());
    }
}

From source file:com.prasanna.android.stacknetwork.QuestionActivity.java

private MenuItem setupFavoriteActionBarIcon() {
    MenuItem favorite = menu.findItem(R.id.menu_favorite);
    if (question != null && question.favorited) {
        favorite.setIcon(R.drawable.favorited);
    } else {/*w ww . j  a  v a 2 s  . c  o  m*/
        favorite.setIcon(R.drawable.favorite);
    }
    return favorite;
}

From source file:net.kourlas.voipms_sms.activities.NewConversationActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    ActionBar actionBar = getSupportActionBar();
    if (actionBar != null) {
        switch (item.getItemId()) {
        case R.id.keyboard_button:
            SearchView searchView = (SearchView) actionBar.getCustomView().findViewById(R.id.search_view);
            if (searchView.getInputType() == (InputType.TYPE_TEXT_VARIATION_PERSON_NAME)) {
                searchView.setInputType(InputType.TYPE_CLASS_PHONE);
                item.setIcon(R.drawable.ic_keyboard_white_24dp);
                item.setTitle(R.string.new_conversation_action_keyboard);
            } else {
                searchView.setInputType(InputType.TYPE_TEXT_VARIATION_PERSON_NAME);
                item.setIcon(R.drawable.ic_dialpad_white_24dp);
                item.setTitle(R.string.new_conversation_action_dialpad);
            }/*from   www.j a v  a 2s  .  c o m*/
            return true;
        }
    }

    return super.onOptionsItemSelected(item);
}

From source file:com.gh4a.activities.GistActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    boolean authorized = Gh4Application.get().isAuthorized();

    MenuItem starAction = menu.findItem(R.id.star);
    starAction.setVisible(authorized);/* w ww  . j  a  v a 2 s. co  m*/
    if (authorized) {
        if (mIsStarred == null) {
            MenuItemCompat.setActionView(starAction, R.layout.ab_loading);
            MenuItemCompat.expandActionView(starAction);
        } else if (mIsStarred) {
            starAction.setTitle(R.string.repo_unstar_action);
            starAction.setIcon(R.drawable.unstar);
        } else {
            starAction.setTitle(R.string.repo_star_action);
            starAction.setIcon(R.drawable.star);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.technoxist.fragment.EntryFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    inflater.inflate(R.menu.entry, menu);

    if (mFavorite) {
        MenuItem item = menu.findItem(R.id.menu_star);
        item.setIcon(R.drawable.rating_important);
    }/*from w w w.  jav a 2 s.co m*/

    super.onCreateOptionsMenu(menu, inflater);
}