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.alfresco.mobile.android.application.extension.samsung.pen.SNoteEditorActionMode.java

private void getMenu(Menu menu) {
    MenuItem mi;
    menu.clear();//from   ww  w.  ja  v a  2 s.co  m

    mi = menu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_DELETE_ID,
            Menu.FIRST + SNoteMenuActionItem.MENU_EDITOR_SETTINGS, R.string.editor_tools_settings);
    mi.setIcon(R.drawable.ic_delete);
    mi.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    // GROUP MENU
    if (selectedSpenObjects.size() > 1) {
        SubMenu groupSubMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
                R.string.editor_group_menu);
        groupSubMenu.setIcon(R.drawable.ic_group);
        groupSubMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

        mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID,
                Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_GROUP_ID, R.string.editor_group);

        mi = groupSubMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID,
                Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_UNGROUP_ID, R.string.editor_ungroup);

        mi.setEnabled(false);
        for (SpenObjectBase obj : selectedSpenObjects) {
            if (obj.getType() == SpenObjectBase.TYPE_CONTAINER) {
                mi.setEnabled(true);
                break;
            }
        }
    }

    // UP MENU
    SubMenu upMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_front_menu);
    upMenu.setIcon(R.drawable.ic_move_up);
    upMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_FORWARD_ID, R.string.editor_forward);

    mi = upMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_TOP_ID, R.string.editor_front);

    // DOWN MENU
    SubMenu downMenu = menu.addSubMenu(Menu.NONE, SNoteMenuActionItem.MENU_EDITOR_TOOLS, Menu.FIRST,
            R.string.editor_back_menu);
    downMenu.setIcon(R.drawable.ic_move_down);
    downMenu.getItem().setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);

    mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BACKWARD_ID, R.string.editor_backward);

    mi = downMenu.add(Menu.NONE, SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID,
            Menu.FIRST + SNoteMenuActionItem.CONTEXT_MENU_MOVE_TO_BOTTOM_ID, R.string.editor_back);
}

From source file:org.camlistore.CamliActivity.java

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

    MenuItem uploadAll = menu.add(Menu.NONE, MENU_UPLOAD_ALL, 0, R.string.upload_all);
    uploadAll.setIcon(android.R.drawable.ic_menu_upload);

    MenuItem stop = menu.add(Menu.NONE, MENU_STOP, 0, R.string.stop);
    stop.setIcon(android.R.drawable.ic_menu_close_clear_cancel);

    MenuItem stopDie = menu.add(Menu.NONE, MENU_STOP_DIE, 0, R.string.stop_die);
    stopDie.setIcon(android.R.drawable.ic_menu_close_clear_cancel);

    MenuItem profiles = menu.add(Menu.NONE, MENU_PROFILES, 0, R.string.profile);
    // TODO(mpl): do we care about this icon? I don't even know where it actually appears.
    profiles.setIcon(android.R.drawable.ic_menu_preferences);

    MenuItem settings = menu.add(Menu.NONE, MENU_SETTINGS, 0, R.string.settings);
    settings.setIcon(android.R.drawable.ic_menu_preferences);

    menu.add(Menu.NONE, MENU_VERSION, 0, R.string.version);
    return true;/*from w  w w  .j  a v  a2  s .c o m*/
}

From source file:com.google.samples.apps.iosched.navigation.AppNavigationViewAsDrawerImpl.java

private void createNavDrawerItems(NavigationModel.NavigationItemEnum[] items) {
    if (mNavigationView != null) {
        Menu menu = mNavigationView.getMenu();
        for (int i = 0; i < items.length; i++) {
            MenuItem item = menu.findItem(items[i].getId());
            if (item != null) {
                item.setVisible(true);//from w w w  . ja v  a2s . com
                item.setIcon(items[i].getIconResource());
                item.setTitle(items[i].getTitleResource());
            } else {
                LOGE(TAG,
                        "Menu Item for navigation item with title " + (items[i].getTitleResource() != 0
                                ? mActivity.getResources().getString(items[i].getTitleResource())
                                : "") + "not found");
            }
        }

        mNavigationView.setNavigationItemSelectedListener(this);
    }
}

From source file:org.kosmakoff.pocketreckoner.ui.MainActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    // Inflate the menu; this adds items to the action bar if it is present.
    getMenuInflater().inflate(R.menu.main, menu);

    switch (currentMenu) {
    case PEOPLE:/*from   w  ww .  j a v  a 2  s .c om*/
        MenuItem addPersonMenuItem = menu.add(Menu.NONE, R.id.menu_item_add_person, 10, R.string.add_person);
        addPersonMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
        addPersonMenuItem.setIcon(R.drawable.ic_social_add_person);
        break;
    case CHECKS:
        MenuItem addCheckMenuItem = menu.add(Menu.NONE, R.id.menu_item_add_check, 10, R.string.add_check);
        addCheckMenuItem.setShowAsActionFlags(MenuItem.SHOW_AS_ACTION_ALWAYS);
        addCheckMenuItem.setIcon(R.drawable.ic_action_new_dark);
        break;
    default:
        break;
    }

    return true;
}

From source file:de.vanita5.twittnuker.util.ThemeUtils.java

public static void wrapMenuItemIcon(@NonNull MenuItem item, int itemColor, int... excludeGroups) {
    if (ArrayUtils.contains(excludeGroups, item.getGroupId()))
        return;//from  w  w w  . ja  va 2s . com
    final Drawable icon = item.getIcon();
    if (icon == null)
        return;
    icon.mutate();
    final Drawable.Callback callback = icon.getCallback();
    final ActionIconDrawable newIcon = new ActionIconDrawable(icon, itemColor);
    newIcon.setCallback(callback);
    item.setIcon(newIcon);
}

From source file:com.keithcassidy.finishline.LineCrossingsFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {

    MenuItem clearListMenuItem = menu.add(R.string.menu_clear_crossing_times);
    clearListMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    clearListMenuItem.setIcon(android.R.drawable.ic_menu_delete);

    clearListMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {

        @Override/* w ww  .  j  a  v  a 2 s .  com*/
        public boolean onMenuItemClick(MenuItem item) {
            try {
                deleteCrossings();
            } catch (Exception e) {
                Log.e(TAG, "onMenuItemClick " + e);
            }
            return true;
        }
    });

    MenuItem shareMenuItem = menu.add(R.string.menu_share);
    shareMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    shareMenuItem.setIcon(android.R.drawable.ic_menu_share);

    shareMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem item) {
            try {
                sendCurrentCrossing();
            } catch (Exception e) {
                Log.e(TAG, "onMenuItemClick " + e);
            }
            return true;
        }
    });

    super.onCreateOptionsMenu(menu, inflater);
}

From source file:com.example.julia.popularmovies.details.DetailFragment.java

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    if (mMovie != null) {
        inflater.inflate(R.menu.detail, menu);
        final MenuItem action_favorite = menu.findItem(R.id.action_favorite);
        action_favorite.setIcon(setFavoriteIcon(isFavorited()));

        MenuItem action_share = menu.findItem(R.id.action_share);
        mShareActionProvider = (ShareActionProvider) MenuItemCompat.getActionProvider(action_share);

        new AsyncTask<Void, Void, Boolean>() {
            @Override/* www  .  j  a  v a 2s.co m*/
            protected Boolean doInBackground(Void... params) {
                return isFavorited();
            }

            @Override
            protected void onPostExecute(Boolean isFavorited) {
                action_favorite.setIcon(setFavoriteIcon(isFavorited));
            }
        }.execute();
    }
    super.onCreateOptionsMenu(menu, inflater);
}

From source file:org.sipdroid.sipua.ui.Sipdroid.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);
    m = menu.add(0, EXIT_MENU_ITEM, 0, R.string.menu_exit);
    m.setIcon(android.R.drawable.ic_menu_close_clear_cancel);
    m = menu.add(0, CONFIGURE_MENU_ITEM, 0, R.string.menu_settings);
    m.setIcon(android.R.drawable.ic_menu_preferences);

    return result;
}

From source file:org.melato.bus.android.activity.ScheduleActivity.java

private void updateAgency(MenuItem browse) {
    if (browse != null) {
        Agency agency = Info.routeManager(this).getAgency(activities.getRouteId());
        Drawable drawable = Info.getAgencyIcon(this, agency);
        if (drawable != null) {
            browse.setIcon(drawable);
        }/*from   w  w  w .  ja v a2  s .  c om*/
        if (agency.getLabel() != null) {
            browse.setTitle(agency.getLabel());
        }
    }
}