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:org.kochka.android.weightlogger.WeightLoggerActivity.java

public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem mClose = menu.add(0, 1, 1, R.string.quit);
    mClose.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    MenuItem mPref = menu.add(0, R.id.item_preferences, 2, R.string.pref);
    mPref.setIcon(android.R.drawable.ic_menu_preferences);
    return (super.onCreateOptionsMenu(menu));
}

From source file:de.stadtrallye.rallyesoft.fragments.TasksOverviewFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem refreshMenuItem = menu.add(Menu.NONE, R.id.refresh_menu, 30, R.string.refresh);
    refreshMenuItem.setIcon(R.drawable.ic_refresh_light);
    refreshMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    MenuItem resize = menu.add(Menu.NONE, R.id.resize_menu, 40, R.string.resize);
    resize.setIcon(R.drawable.ic_center_light);
    resize.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}

From source file:com.hbm.devices.scan.ui.android.ScanActivity.java

@Override
public boolean onCreateOptionsMenu(@NonNull Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.device_list_actions, menu);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint(getString(R.string.search_hint));
    searchView.setImeOptions(EditorInfo.IME_ACTION_DONE);
    searchView.setOnQueryTextListener(new OnQueryTextListener() {
        @Override/*from  ww w  . j  av  a  2 s .c o  m*/
        public boolean onQueryTextSubmit(final String query) {
            searchView.clearFocus();
            adapter.setFilterString(query);
            return true;
        }

        @Override
        public boolean onQueryTextChange(final String newText) {
            adapter.setFilterString(newText);
            return true;
        }
    });
    adapter.setFilterString(null);

    final MenuItem pauseItem = menu.findItem(R.id.action_pause_control);
    if (adapter.isPaused()) {
        pauseItem.setIcon(R.drawable.ic_action_play);
    } else {
        pauseItem.setIcon(R.drawable.ic_action_pause);
    }
    return true;
}

From source file:joshuatee.wx.CommonActionBarFragment.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.cab, menu);//from w  ww  .  j a va 2 s.  co m

    if (theme_blue_current.contains("white")) {
        MenuItem cloud = menu.findItem(R.id.action_cloud);
        cloud.setIcon(R.drawable.cloud_dark);
        MenuItem radar = menu.findItem(R.id.action_radar);
        radar.setIcon(R.drawable.radar_dark);
        MenuItem forecast = menu.findItem(R.id.action_forecast);
        forecast.setIcon(R.drawable.forecast_dark);
        MenuItem afd = menu.findItem(R.id.action_afd);
        afd.setIcon(R.drawable.afd_dark);
        //MenuItem alerts = menu.findItem(R.id.action_alert);
        //alerts.setIcon(R.drawable.alert_dark);
        MenuItem mosaic = menu.findItem(R.id.action_radar_mosaic);
        mosaic.setIcon(R.drawable.map_dark);
    }

    comma = Pattern.compile(",");

    return true;
}

From source file:ru.appsm.inapphelp.fragments.NewIssueFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    // Inflate the menu; this adds items to the action bar if it is present.
    inflater.inflate(R.menu.iah_issue_menu, menu);

    MenuItem clearMenu = menu.findItem(R.id.clearItem);
    MenuItemCompat.setShowAsAction(clearMenu, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);

    MenuItem doneMenu = menu.findItem(R.id.doneItem);

    doneMenu.setIcon(getResources().getDrawable(R.drawable.iah_action_forward));
    doneMenu.setTitle(getResources().getText(R.string.iah_next));

    MenuItemCompat.setShowAsAction(doneMenu, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
}

From source file:com.mifos.mifosxdroid.online.CollectionSheetFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    menu.clear();//from w  ww .  j a va 2 s. c o m

    MenuItem mItemSearch = menu.add(Menu.NONE, MENU_ITEM_SEARCH, Menu.NONE, getString(R.string.search));
    //        mItemSearch.setIcon(new IconDrawable(getActivity(), MaterialIcons.md_search)
    //                .colorRes(Color.WHITE)
    //                .actionBarSize());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mItemSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    MenuItem mItemRefresh = menu.add(Menu.NONE, MENU_ITEM_REFRESH, Menu.NONE, getString(R.string.refresh));
    mItemRefresh.setIcon(
            new IconDrawable(getActivity(), MaterialIcons.md_refresh).colorRes(Color.WHITE).actionBarSize());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mItemRefresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    MenuItem mItemSave = menu.add(Menu.NONE, MENU_ITEM_SAVE, Menu.NONE, getString(R.string.save));
    mItemSave.setIcon(
            new IconDrawable(getActivity(), MaterialIcons.md_save).colorRes(Color.WHITE).actionBarSize());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mItemSave.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    super.onPrepareOptionsMenu(menu);

}

From source file:net.pmarks.chromadoze.ChromaDoze.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    menu.findItem(MENU_PLAY_STOP).setIcon(mServiceActive ? R.drawable.av_stop : R.drawable.av_play);
    MenuItem mi = menu.findItem(MENU_LOCK);
    if (mi != null) {
        mi.setIcon(getLockIcon());
    }/*from   ww w  . j av a  2  s  .c  o m*/
    return super.onPrepareOptionsMenu(menu);
}

From source file:com.mifos.mifosxdroid.online.collectionsheet.CollectionSheetFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {

    menu.clear();/*  w ww. j av a 2  s.  co m*/

    MenuItem mItemSearch = menu.add(Menu.NONE, MENU_ITEM_SEARCH, Menu.NONE, getString(R.string.search));
    //        mItemSearch.setIcon(new IconDrawable(getActivity(), MaterialIcons.md_search)
    //                .colorRes(Color.WHITE)
    //                .actionBarSize());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mItemSearch.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    }

    MenuItem mItemRefresh = menu.add(Menu.NONE, MENU_ITEM_REFRESH, Menu.NONE, getString(R.string.refresh));
    mItemRefresh.setIcon(
            new IconDrawable(getActivity(), MaterialIcons.md_refresh).colorRes(R.color.white).actionBarSize());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mItemRefresh.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    MenuItem mItemSave = menu.add(Menu.NONE, MENU_ITEM_SAVE, Menu.NONE, getString(R.string.save));
    mItemSave.setIcon(
            new IconDrawable(getActivity(), MaterialIcons.md_save).colorRes(R.color.white).actionBarSize());
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
        mItemSave.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }

    super.onPrepareOptionsMenu(menu);

}

From source file:com.examples.abelanav2.ui.UploadFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem uploadMenu = menu.add(R.string.upload_menu_action);
    uploadMenu.setIcon(R.drawable.ic_done_white_24dp);
    uploadMenu.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    uploadMenu.setOnMenuItemClickListener(this);
    super.onCreateOptionsMenu(menu, inflater);
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater 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();/*from  ww w  .j a  v a 2 s.c o m*/

    ViewHelper.changeSearchViewTextColor(mSearchView, color, ColorHelper.setColorAlpha(color, 0.6f));
    View view = mSearchView.findViewById(android.support.v7.appcompat.R.id.search_plate);
    if (view != null)
        view.setBackgroundColor(Color.TRANSPARENT);

    ImageView closeIcon = (ImageView) mSearchView
            .findViewById(android.support.v7.appcompat.R.id.search_close_btn);
    if (closeIcon != null)
        closeIcon.setImageResource(R.drawable.ic_toolbar_close);

    ImageView searchIcon = (ImageView) mSearchView
            .findViewById(android.support.v7.appcompat.R.id.search_mag_icon);
    ViewHelper.removeSearchViewSearchIcon(searchIcon);

    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;
        }
    });
}