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.owncloud.android.ui.fragment.contactsbackup.ContactListFragment.java

private void setSelectAllMenuItem(MenuItem selectAll, boolean checked) {
    selectAll.setChecked(checked);//from  w  w w .j  a va2 s  . c  o  m
    if (checked) {
        selectAll.setIcon(R.drawable.ic_select_none);
    } else {
        selectAll.setIcon(R.drawable.ic_select_all);
    }
}

From source file:nl.spellenclubeindhoven.dominionshuffle.SelectActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(Menu.NONE, MENU_SORT, Menu.NONE, R.string.menu_sort);
    item.setIcon(android.R.drawable.ic_menu_sort_alphabetically);

    item = menu.add(Menu.NONE, MENU_CLEAR_ALL, Menu.NONE, R.string.menu_clear_all);
    item.setIcon(R.drawable.clear_all);/*from ww w  .  j  a  v a  2 s  .c  o m*/

    item = menu.add(Menu.NONE, MENU_LOAD, Menu.NONE, R.string.menu_load);
    item.setIcon(android.R.drawable.ic_menu_upload);

    item = menu.add(Menu.NONE, MENU_SAVE, Menu.NONE, R.string.menu_save);
    item.setIcon(android.R.drawable.ic_menu_save);

    item = menu.add(Menu.NONE, MENU_SETTINGS, Menu.NONE, R.string.menu_settings);
    item.setIcon(R.drawable.globe);

    item = menu.add(Menu.NONE, MENU_LAST_RESULT, Menu.NONE, R.string.menu_last_result);
    item.setIcon(R.drawable.last_result);

    item = menu.add(Menu.NONE, MENU_ABOUT, Menu.NONE, R.string.menu_about);
    item.setIcon(android.R.drawable.stat_sys_warning);

    return super.onCreateOptionsMenu(menu);
}

From source file:de.vanita5.twittnuker.fragment.support.UserListDetailsFragment.java

private void setMenu(final Menu menu) {
    final AsyncTwitterWrapper twitter = getTwitterWrapper();
    final ParcelableUserList userList = mUserList;
    final MenuItem followItem = menu.findItem(MENU_FOLLOW);
    if (followItem != null) {
        followItem.setEnabled(userList != null);
        if (userList == null) {
            followItem.setIcon(android.R.color.transparent);
        }//www  .  ja v  a 2 s  .  com
    }
    if (twitter == null || userList == null)
        return;
    final boolean isMyList = userList.user_id == userList.account_id;
    setMenuItemAvailability(menu, MENU_EDIT, isMyList);
    setMenuItemAvailability(menu, MENU_ADD, isMyList);
    setMenuItemAvailability(menu, MENU_DELETE, isMyList);
    final boolean isFollowing = userList.is_following;
    if (followItem != null) {
        followItem.setVisible(!isMyList);
        if (isFollowing) {
            followItem.setIcon(R.drawable.ic_iconic_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_iconic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
}

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

/**
 *   //from   ww w  .  java  2 s  . co  m
 */
@Override
public boolean onOptionsItemSelected(MenuItem item) {
    int id = item.getItemId();

    if (id == R.id.action_bluetooth) {
        if (mBtAdapter != null) {
            if (mBtAdapter.isEnabled()) {
                mBtAdapter.disable();
                Toast.makeText(this, "Bluetooth ?", Toast.LENGTH_SHORT).show();
                item.setIcon(R.drawable.bt_off);
            } else {
                mBtAdapter.enable();
                Toast.makeText(this, "Bluetooth ", Toast.LENGTH_SHORT).show();
                item.setIcon(R.drawable.bt_on);
            }
        }

        return true;
    }

    return super.onOptionsItemSelected(item);
}

From source file:me.acristoffers.tracker.activities.PackageListActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.menu_package_list, menu);

    MenuItem item = menu.findItem(R.id.toggle_inactive);

    final boolean showInactive = packageListFragment.isShowInactive();

    item.setTitle(showInactive ? R.string.hide_inactive : R.string.show_inactive);
    item.setIcon(showInactive ? R.drawable.ic_visibility_off_black_48dp : R.drawable.ic_visibility_black_48dp);

    item = menu.findItem(R.id.search);//from w ww .  j  a  va  2s  .c  o  m
    if (item != null) {
        final SearchView searchView = (SearchView) item.getActionView();
        if (searchView != null) {
            searchView.setQueryHint(getResources().getString(R.string.filter));

            searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
                @Override
                public boolean onQueryTextSubmit(final String query) {
                    filter(query);
                    return true;
                }

                @Override
                public boolean onQueryTextChange(final String newText) {
                    // Workaround this:
                    // http://stackoverflow.com/questions/9327826/searchviews-oncloselistener-doesnt-work/12975254#12975254
                    if (newText.isEmpty()) {
                        filter(null);
                    } else {
                        filter(newText);
                    }

                    return true;
                }
            });

            searchView.setOnCloseListener(new SearchView.OnCloseListener() {
                @Override
                public boolean onClose() {
                    filter(null);
                    return true;
                }
            });
        }
    }

    return true;
}

From source file:com.primalpond.hunt.TheHunt.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_terraform:
        mGLView.post(new Runnable() {
            public void run() {
                mGLView.mRenderer.regenerateWorld();
            }//from  w  ww.ja  v  a2s . c om
        });
        break;
    case R.id.action_play_services:
        if (isSignedIn()) {
            signOut();
            item.setIcon(getResources().getDrawable(R.drawable.games_controller_white));
        } else {
            beginUserInitiatedSignIn();
        }
        break;
    case R.id.action_show_scoreboard:
        if (isSignedIn()) {
            if (mGLView != null && mGLView.mRenderer != null) {
                mGamesClient.submitScore(LEADERBOARD_ID, mGLView.mRenderer.mCaughtCounter);
            }
            startActivityForResult(mGamesClient.getLeaderboardIntent(LEADERBOARD_ID), REQUEST_LEADERBOARD);
        } else {
            beginUserInitiatedSignIn();
            mToShowScoreOnSuccess = true;
        }
        break;
    case R.id.action_help:
        //         Intent i = new Intent(this, Tutorial.class);
        //         startActivityForResult(i, REQ_TUTORIAL);
        beginTutorial();
        break;
    default:
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:de.grobox.liberario.fragments.DirectionsFragment.java

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

    // in some cases getActivity() and getContext() can be null, so get it somewhere else
    Context context = getContext();

    MenuItem expandItem = menu.findItem(R.id.action_navigation_expand);
    if (ui.products.getVisibility() == GONE) {
        expandItem.setIcon(getToolbarDrawable(context, R.drawable.ic_action_navigation_unfold_more));
    } else {//from  w  w  w .  j  a  v a  2  s.co  m
        expandItem.setIcon(getToolbarDrawable(context, R.drawable.ic_action_navigation_unfold_less));
    }

    MenuItem swapItem = menu.findItem(R.id.action_swap_locations);
    fixToolbarIcon(context, swapItem);

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.chromium.chrome.browser.preferences.website.SingleCategoryPreferences.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    menu.clear();//from   w  ww.ja  v a2s  .  c o m
    inflater.inflate(R.menu.website_preferences_menu, menu);

    MenuItem searchItem = menu.findItem(R.id.search);
    mSearchView = (SearchView) MenuItemCompat.getActionView(searchItem);
    mSearchView.setImeOptions(EditorInfo.IME_FLAG_NO_FULLSCREEN);
    SearchView.OnQueryTextListener queryTextListener = new SearchView.OnQueryTextListener() {
        @Override
        public boolean onQueryTextSubmit(String query) {
            return true;
        }

        @Override
        public boolean onQueryTextChange(String query) {
            if (query.equals(mSearch))
                return true;

            mSearch = query;
            getInfoForOrigins();
            return true;
        }
    };
    mSearchView.setOnQueryTextListener(queryTextListener);

    if (mCategory.showProtectedMediaSites()) {
        // Add a menu item to reset protected media identifier device credentials.
        MenuItem resetMenu = menu.add(Menu.NONE, Menu.NONE, Menu.NONE, R.string.reset_device_credentials);
        resetMenu.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
            @Override
            public boolean onMenuItemClick(MenuItem menuItem) {
                ProtectedContentResetCredentialConfirmDialogFragment.newInstance(SingleCategoryPreferences.this)
                        .show(getFragmentManager(), null);
                return true;
            }
        });
    }

    MenuItem help = menu.add(Menu.NONE, R.id.menu_id_targeted_help, Menu.NONE, R.string.menu_help);
    help.setIcon(R.drawable.ic_help_and_feedback);
}

From source file:com.topfeeds4j.sample.app.activities.MainActivity.java

private void setViewModeMenuItem(MenuItem mi) {
    int mode = Prefs.getInstance().getViewMode();
    mi.setIcon(mode == Prefs.VIEW_MODE_SINGLE ? R.drawable.ic_multi_mode : R.drawable.ic_single_mode);
}

From source file:goo.TeaTimer.TimerActivity.java

/** { @inheritDoc} */
@Override//ww  w.  ja v  a2 s  .c  o  m
public boolean onCreateOptionsMenu(Menu menu) {
    MenuItem item = menu.add(0, PREF, 0, getResources().getString(R.string.prefs));
    MenuItem about = menu.add(1, 1, 0, getResources().getString(R.string.about));

    item.setIcon(android.R.drawable.ic_menu_preferences);
    about.setIcon(android.R.drawable.ic_menu_info_details);

    return super.onCreateOptionsMenu(menu);
}