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:fr.bmartel.android.iotf.app.NotificationActivity.java

@Override
public void displayDisconnect(MenuItem menuItem) {
    menuItem.setIcon(R.drawable.disconnect2);
}

From source file:com.mikepenz.iconics.sample.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu items for use in the action bar
    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_main, menu);

    ///* w ww.jav  a 2  s .co m*/
    menu.findItem(R.id.search).setIcon(new IconicsDrawable(this, MaterialDesignIconic.Icon.gmi_search)
            .color(Color.WHITE).sizeDp(24).respectFontBounds(true));

    if (android.os.Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        final SearchView searchView = (SearchView) menu.findItem(R.id.search).getActionView();
        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {

            @Override
            public boolean onQueryTextSubmit(String s) {
                search(s);
                return true;
            }

            @Override
            public boolean onQueryTextChange(String s) {
                search(s);
                return true;
            }

            private void search(String s) {
                mCurrentSearch = s;

                if (mDrawer != null) {
                    int count = 0;
                    for (ITypeface font : mFonts) {
                        int foundCount = 0;
                        if (font.getIcons() != null) {
                            for (String icon : font.getIcons()) {
                                if (icon.toLowerCase().contains(s.toLowerCase())) {
                                    foundCount++;
                                }
                            }
                        }
                        mDrawer.updateBadge(count, new StringHolder(foundCount + ""));

                        count++;
                    }
                }

                //filter out the current fragment
                if (mIconsFragment != null)
                    mIconsFragment.onSearch(s);
            }
        });
    } else {
        menu.findItem(R.id.search).setVisible(false);
    }

    MenuItem menuItem = menu.findItem(R.id.action_opensource);
    menuItem.setIcon(new IconicsDrawable(this, FontAwesome.Icon.faw_github).actionBar().color(Color.WHITE));
    return super.onCreateOptionsMenu(menu);
}

From source file:com.github.nicktgn.mvp_sample.ui.NoteFragment.java

@Override
public void enableUndo(boolean enable) {
    MenuItem undo = mEditToolsMenu.getMenu().findItem(R.id.action_undo);
    undo.setEnabled(enable);/*from   ww  w.  ja  v a2  s .co m*/
    undo.setIcon(enable ? R.drawable.ic_undo_white_24dp : R.drawable.ic_undo_grey_700_24dp);
}

From source file:com.github.nicktgn.mvp_sample.ui.NoteFragment.java

@Override
public void enableRedo(boolean enable) {
    MenuItem redo = mEditToolsMenu.getMenu().findItem(R.id.action_redo);
    redo.setEnabled(enable);//from  w w  w .  j a  v  a2s.c o  m
    redo.setIcon(enable ? R.drawable.ic_redo_white_24dp : R.drawable.ic_redo_grey_700_24dp);
}

From source file:de.tap.easy_xkcd.fragments.overview.OverviewRecyclerBaseFragment.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_favorite:
        if (prefHelper.overviewFav()) {
            item.setIcon(R.drawable.ic_favorite_outline);
            item.setTitle(R.string.nv_favorites);
        } else {/*from  w w  w .j  a v  a  2s . c  o  m*/
            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_boomark:
        super.goToComic(bookmark - 1);
        break;
    case R.id.action_unread:
        databaseManager.setComicsUnread();
        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:org.lumicall.android.sip.RegisterAccount.java

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

    MenuItem m = menu.add(0, ABOUT_MENU_ITEM, 0, R.string.menu_about);
    m.setIcon(android.R.drawable.ic_menu_info_details);

    return result;
}

From source file:com.coinblesk.client.TransactionDetailActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.tx_detail_menu, menu);
    MenuItem openItem = menu.findItem(R.id.action_tx_open_web);
    openItem.setIcon(UIUtils.tintIconWhite(openItem.getIcon(), this));

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

From source file:gov.wa.wsdot.android.wsdot.ui.MountainPassItemActivity.java

private void toggleStar(MenuItem item) {
    resolver = getContentResolver();/* ww  w  .j  av a 2s . c om*/

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        try {
            ContentValues values = new ContentValues();
            values.put(MountainPasses.MOUNTAIN_PASS_IS_STARRED, 0);
            resolver.update(MountainPasses.CONTENT_URI, values, MountainPasses.MOUNTAIN_PASS_ID + "=?",
                    new String[] { Integer.toString(mId) });

            Toast.makeText(this, R.string.remove_favorite, Toast.LENGTH_SHORT).show();
            mIsStarred = false;
        } catch (Exception e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            Log.e("MountainPassItemActivity", "Error: " + e.getMessage());
        }
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        try {
            ContentValues values = new ContentValues();
            values.put(MountainPasses.MOUNTAIN_PASS_IS_STARRED, 1);
            resolver.update(MountainPasses.CONTENT_URI, values, MountainPasses.MOUNTAIN_PASS_ID + "=?",
                    new String[] { Integer.toString(mId) });

            Toast.makeText(this, R.string.add_favorite, Toast.LENGTH_SHORT).show();
            mIsStarred = true;
        } catch (Exception e) {
            Toast.makeText(this, e.getMessage(), Toast.LENGTH_SHORT).show();
            Log.e("MountainPassItemActivity", "Error: " + e.getMessage());
        }
    }
}

From source file:cf.obsessiveorange.rhcareerfairlayout.ui.fragments.VPCompaniesFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    MenuItem searchBtn = menu.findItem(R.id.action_search);
    searchBtn.setVisible(true);/* w  w w  .j av a 2 s  .co m*/

    SubMenu selectionMenu = menu.addSubMenu(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_edit)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectionMenu.getItem().setTitle(getResources().getString(R.string.selection_options_btn));
    selectionMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    MenuItem selectAllItem = selectionMenu.add(getResources().getString(R.string.btn_select_all));
    selectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_check_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    selectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    selectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Selected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(true);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });

    MenuItem deselectAllItem = selectionMenu.add(getResources().getString(R.string.btn_deselect_all));
    deselectAllItem.setIcon(new IconDrawable(this.getActivity(), Iconify.IconValue.fa_square_o)
            .colorRes(R.color.accentNoTransparency).actionBarSize());
    deselectAllItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    deselectAllItem.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            Toast.makeText(getActivity(), "Deselected all items", Toast.LENGTH_SHORT).show();

            try {
                DBManager.setFilteredCompaniesSelected(false);
            } catch (SQLException e) {
                e.printStackTrace();
            }

            ((CompaniesCellAdapter) recyclerView.getAdapter()).refreshData();

            synchronized (RHCareerFairLayout.refreshMapNotifier) {
                RHCareerFairLayout.refreshMapNotifier.notifyChanged();
            }

            return true;
        }
    });
}

From source file:org.chromium.chrome.browser.preferences.Preferences.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    // By default, every screen in Settings shows a "Help & feedback" menu item.
    MenuItem help = menu.add(Menu.NONE, R.id.menu_id_help_general, Menu.CATEGORY_SECONDARY, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
    return true;//from   w  w  w  .  j a v  a 2 s.com
}