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.github.longkai.zhihu.ui.HotItemsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem search = menu.add(android.R.string.search_go);
    search.setIcon(R.drawable.action_search_light);
    // earn some room in action bar
    MenuItemCompat.setShowAsAction(search, MenuItemCompat.SHOW_AS_ACTION_ALWAYS);
    final View searchView = SearchViewCompat.newSearchView(getActivity());
    if (searchView != null) {
        SearchViewCompat.setOnQueryTextListener(searchView, new SearchViewCompat.OnQueryTextListenerCompat() {
            @Override//from   w  w w  .ja v  a2  s  .  c  o m
            public boolean onQueryTextChange(String newText) {
                String newFilter = !TextUtils.isEmpty(newText) ? newText : null;
                if (keywords == null && newFilter == null) {
                    return true;
                }
                if (keywords != null && keywords.equals(newFilter)) {
                    return true;
                }
                keywords = newFilter;
                getLoaderManager().restartLoader(0, null, HotItemsFragment.this);
                return true;
            }
        });
        SearchViewCompat.setOnCloseListener(searchView, new SearchViewCompat.OnCloseListenerCompat() {
            @Override
            public boolean onClose() {
                if (!TextUtils.isEmpty(SearchViewCompat.getQuery(searchView))) {
                    SearchViewCompat.setQuery(searchView, null, true);
                    return true;
                }
                return false;
            }

        });
        MenuItemCompat.setActionView(search, searchView);
    }
}

From source file:cn.androidy.materialdesignsample.animations.CardFlipActivity.java

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

    // Add either a "photo" or "finish" button to the action bar, depending on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_flip, Menu.NONE,
            mShowingBack ? R.string.action_photo : R.string.action_info);
    item.setIcon(mShowingBack ? R.drawable.ic_action_photo : R.drawable.ic_action_info);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;//w w w .ja  v a 2  s .  c  o m
}

From source file:com.zyq.uitoucheventtest.animator.CardFlipActivity.java

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

    // Add either a "photo" or "finish" button to the action bar, depending on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_flip, Menu.NONE,
            mShowingBack ? R.string.action_photo : R.string.action_info);
    item.setIcon(mShowingBack ? R.mipmap.ic_action_photo : R.mipmap.ic_action_info);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;/*from   w  w  w .ja v a 2  s.  c  om*/
}

From source file:com.money.manager.ex.search.SearchActivity.java

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

    UIHelper ui = new UIHelper(this);

    // Add Search icon.
    getMenuInflater().inflate(R.menu.menu_search, menu);
    MenuItem item = menu.findItem(R.id.searchMenuItem);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
    item.setIcon(ui.getIcon(GoogleMaterial.Icon.gmd_search));
    // show this menu item last

    return true;/*from   w  w  w. j a  v a 2 s  .  c  om*/
}

From source file:org.catnut.fragment.TimelineFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.add(Menu.NONE, R.id.refresh, Menu.NONE, R.string.refresh)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER); // prefer actionbar refresh
    menu.add(Menu.NONE, R.id.action_back_top, Menu.NONE, getString(R.string.back_to_top))
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
    // ??//  w w w .j av a  2 s.  c o m
    MenuItem search = menu.add(android.R.string.search_go);
    search.setIcon(R.drawable.ic_title_search_default);
    search.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM | MenuItem.SHOW_AS_ACTION_COLLAPSE_ACTION_VIEW);
    mSearchView = VividSearchView.getSearchView(getActivity());
    mSearchView.setOnQueryTextListener(this);
    mSearchView.setOnCloseListener(this);
    search.setActionView(mSearchView);
}

From source file:com.example.cardflipanimation.CardFlipActivity.java

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

    // Add either a "photo" or "finish" button to the action bar, depending
    // on which page
    // is currently selected.
    MenuItem item = menu.add(Menu.NONE, R.id.action_flip, Menu.NONE,
            mShowingBack ? R.string.action_photo : R.string.action_info);
    item.setIcon(mShowingBack ? R.drawable.ic_action_photo : R.drawable.ic_action_info);
    item.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    return true;//from w w w .  j  av a 2  s.  c  o m
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    Log.d(TAG, "onCreateOptionsMenu " + hashCode());
    super.onCreateOptionsMenu(menu, inflater);
    inflater.inflate(R.menu.options_sign_browser, menu);
    final MenuItem item = menu.findItem(R.id.action_toggle_starred);
    if (this.showStarredOnly) {
        item.setIcon(R.drawable.ic_sign_browser_grade_checked);
    } else {/*w  w  w. ja  v  a  2 s .  co m*/
        item.setIcon(R.drawable.ic_sign_browser_grade_no_stroke);
    }
    final SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
    final MenuItem searchItem = menu.findItem(R.id.action_search);
    final SearchView searchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
}

From source file:com.cryart.sabbathschool.view.SSReadingActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    getMenuInflater().inflate(R.menu.ss_reading_menu, menu);
    MenuItem menuItem = menu.findItem(R.id.ss_reading_menu_display_options);
    menuItem.setIcon(
            new IconicsDrawable(this).icon(GoogleMaterial.Icon.gmd_text_format).color(Color.WHITE).sizeDp(16));
    return true;//from  w  w w.  j a v a 2s . co  m
}

From source file:com.bellman.bible.android.view.activity.base.actionbar.QuickActionButton.java

protected void update(MenuItem menuItem) {
    // canShow means must show because we rely on AB logic
    menuItem.setVisible(canShow());/*www  .j  av  a 2  s  . co m*/

    menuItem.setTitle(getTitle());

    int iconResId = getIcon();
    if (iconResId != NO_ICON) {
        menuItem.setIcon(iconResId);
    }
}

From source file:jp.morimotor.beaconattend.HelpActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    // ?????//from w w  w .  j  av a2  s. c  om
    MenuItem actionItem = menu.add("infoButton");

    // SHOW_AS_ACTION_IF_ROOM:???
    actionItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // 
    actionItem.setIcon(R.drawable.ic_info_outline_white_24dp);

    return true;
}