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.vanita5.twittnuker.fragment.support.UserListFragment.java

@Override
public void onPrepareOptionsMenu(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);
        }/*from  w w w . j av  a  2  s .  c  om*/
    }
    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_action_cancel);
            followItem.setTitle(R.string.unsubscribe);
        } else {
            followItem.setIcon(R.drawable.ic_action_add);
            followItem.setTitle(R.string.subscribe);
        }
    }
}

From source file:com.dldzkj.app.renxing.mainfragment.MyPostFragment0.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_settings:
        if (!btnEnable) {
            return true;
        }/* w w  w.ja  v a2 s  . co m*/
        if (datas.size() == 0) {
            Toast.makeText(this.getActivity(), "?", Toast.LENGTH_SHORT).show();
        } else {
            if (adapter.isDeleteMode()) {//?
                item.setIcon(R.drawable.ic_delede);
                item.setTitle("");
                bottom.setVisibility(View.GONE);
                adapter.setDeleteMode(false);
            } else {//
                item.setIcon(null);
                item.setTitle("?");
                bottom.setVisibility(View.VISIBLE);
                adapter.setDeleteMode(true);
            }
            adapter.notifyDataSetChanged();
        }
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.ibm.mf.geofence.demo.MapsActivity.java

@Override
public boolean onOptionsItemSelected(final MenuItem item) {
    switch (item.getItemId()) {
    case R.id.action_tracking:
        trackingEnabled = !trackingEnabled;
        log.debug("tracking is now " + (trackingEnabled ? "enabled" : "disabled"));
        settings.putBoolean(TRACKING_ENABLED_KEY, trackingEnabled).commit();
        item.setIcon(trackingEnabled ? R.mipmap.on : R.mipmap.off);
        log.debug(String.format("onOptionsItemSelected() tracking is now %s",
                trackingEnabled ? "enabled" : "disabled"));
        break;//from   ww  w .j a v  a2s  .  com
    case R.id.action_mail_log:
        DemoUtils.sendLogByMail(this);
        break;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.nextgis.mobile.activity.MainActivity.java

private void setTrackItem(MenuItem item, int title, int icon) {
    if (null != item) {
        item.setTitle(title);//from   w  ww.j  a v a 2s  .  com
        item.setIcon(icon);
    }
}

From source file:org.alfresco.mobile.android.application.accounts.fragment.AccountDetailsFragment.java

public void getMenu(Menu menu) {
    MenuItem mi;

    if (acc.getActivation() == null) {
        mi = menu.add(Menu.NONE, MenuActionItem.MENU_ACCOUNT_EDIT,
                Menu.FIRST + MenuActionItem.MENU_ACCOUNT_EDIT,
                String.format(getString(R.string.account_edit_hint), acc.getDescription()));
        mi.setIcon(R.drawable.ic_edit);
        mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    }//from ww w.java  2s .c o  m

    mi = menu.add(Menu.NONE, MenuActionItem.MENU_ACCOUNT_DELETE,
            Menu.FIRST + MenuActionItem.MENU_ACCOUNT_DELETE,
            String.format(getString(R.string.account_delete_hint), acc.getDescription()));
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

From source file:com.cyeam.cInterphone.ui.CInterphone.java

@TargetApi(Build.VERSION_CODES.HONEYCOMB)
@Override/*from w  w w. j a  va2  s.c  o  m*/
public boolean onCreateOptionsMenu(Menu menu) {
    boolean result = super.onCreateOptionsMenu(menu);

    MenuItem m;
    // m = menu.add(0, TEST1, 0, R.string.test);
    // m.setIcon(android.R.drawable.ic_menu_call);
    // m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);
    //
    // m = menu.add(0, TEST2, 0, R.string.test);
    // m.setIcon(android.R.drawable.ic_menu_gallery);
    // m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    m = menu.add(0, CONFIGURE_MENU_ITEM, 0, R.string.menu_settings);
    m.setIcon(android.R.drawable.ic_menu_preferences);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

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

    m = menu.add(0, EXIT_MENU_ITEM, 0, R.string.menu_exit);
    m.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    m.setShowAsAction(m.SHOW_AS_ACTION_IF_ROOM);

    return result;
}

From source file:tv.acfun.a63.ArticleActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    if (AcApp.getViewMode() != Constants.MODE_COMMIC && !isWebMode) {
        getMenuInflater().inflate(R.menu.article_options_menu, menu);
        MenuItem actionItem = menu.findItem(R.id.menu_item_share_action_provider_action_bar);
        if (ActionBarUtil.hasSB()) {
            MenuItemCompat.setShowAsAction(actionItem, MenuItemCompat.SHOW_AS_ACTION_NEVER);
        }/*from   w w w .jav a  2 s.  c  o  m*/
        ShareActionProvider actionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(actionItem);
        actionProvider.setShareHistoryFileName(ShareActionProvider.DEFAULT_SHARE_HISTORY_FILE_NAME);
        actionProvider.setShareIntent(createShareIntent());
        if (isFaved) {
            MenuItem fav = menu.findItem(R.id.menu_item_fav_action);
            fav.setIcon(R.drawable.rating_favorite_p);
            fav.setTitle("??");
        }

        MenuItem item = menu.add(0, android.R.id.button1, 0, R.string.font_size)
                .setIcon(R.drawable.ic_text_size);
        MenuItemCompat.setShowAsAction(item, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    }
    return super.onCreateOptionsMenu(menu);
}

From source file:com.docd.purefm.ui.fragments.BrowserFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);
    final AbstractBrowserActivity activity = getBrowserActivity();
    if (activity.shouldShowBrowserFragmentMenu()) {
        inflater.inflate(R.menu.browser, menu);

        // TODO it returns true even on devices that don't have the physical key.
        // Find a better method to detect search hardware button
        //if (KeyCharacterMap.deviceHasKey(KeyEvent.KEYCODE_SEARCH)) {
        //    menu.removeItem(R.id.menu_search);
        //}/*from  w w  w.j a  v a  2  s.  c  om*/

        final MenuItem content = menu.findItem(android.R.id.content);
        if (content == null) {
            throw new RuntimeException("Inflated menu item should contain android.R.id.content");
        }

        final Settings settings = Settings.getInstance(activity);
        switch (settings.getListAppearance()) {
        case LIST:
            content.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_view_as_grid))
                    .setTitle(R.string.menu_view_as_grid).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            break;

        case GRID:
            content.setIcon(ThemeUtils.getDrawableNonNull(activity, R.attr.ic_menu_view_as_list))
                    .setTitle(R.string.menu_view_as_list).setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
            break;

        default:
            throw new IllegalArgumentException("Unexpected ListAppearance:" + settings.getListAppearance());
        }

        if (ClipBoard.isEmpty()) {
            menu.removeItem(android.R.id.paste);
        }
    }
}

From source file:com.sj.android.appusage.activities.UsageListFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    // TODO Auto-generated method stub
    MenuItem filterMenu = (MenuItem) menu.findItem(R.id.filter_menu);
    if (UsageSharedPrefernceHelper.isFilterMode(mActivity)) {
        filterMenu.setIcon(R.drawable.ic_select_all_white_24dp);
        filterMenu.setTitle(R.string.string_all);
    } else {/* w  w  w.  ja v a2 s.c  o m*/
        filterMenu.setIcon(R.drawable.ic_filter_list_white_24dp);
        filterMenu.setTitle(R.string.string_filter);
    }

    MenuItem menuItemSortBy = menu.findItem(R.id.action_sort_by);
    MenuItem menuItemFilter = (MenuItem) menu.findItem(R.id.filter_menu);

    if (mViewPager != null) {
        switch (mViewPager.getCurrentItem()) {
        case 0:
            if (mAppDataListAdapter != null && !mAppDataListAdapter.isEmpty()) {
                menuItemFilter.setVisible(true);
            }
            break;
        case 1:
            menuItemSortBy.setVisible(false);
            menuItemFilter.setVisible(false);
            break;
        default:
            break;
        }
    }

    super.onPrepareOptionsMenu(menu);
}

From source file:com.money.manager.ex.investment.watchlist.WatchlistFragment.java

/**
 * Called once when the menu is being created.
 *//* ww  w .j  av a 2 s . c o m*/
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    super.onCreateOptionsMenu(menu, inflater);

    // add options menu for watchlist
    inflater.inflate(R.menu.menu_watchlist, menu);

    // custom icons

    UIHelper uiHelper = new UIHelper(getActivity());
    IconicsDrawable icon;
    MenuItem menuItem;

    menuItem = menu.findItem(R.id.menu_update_prices);
    if (menuItem != null) {
        icon = uiHelper.getIcon(GoogleMaterial.Icon.gmd_file_download);
        menuItem.setIcon(icon);
    }

    menuItem = menu.findItem(R.id.menu_export_prices);
    if (menuItem != null) {
        icon = uiHelper.getIcon(GoogleMaterial.Icon.gmd_share);
        menuItem.setIcon(icon);
    }

    menuItem = menu.findItem(R.id.menu_purge_history);
    if (menuItem != null) {
        icon = uiHelper.getIcon(GoogleMaterial.Icon.gmd_content_cut);
        menuItem.setIcon(icon);
    }

    // call create option menu of fragment
    mDataFragment.onCreateOptionsMenu(menu, inflater);
}