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.doomy.padlock.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {

    MenuItem mItem = menu.findItem(R.id.action_adb);
    mPrefADB = mPreferences.getBoolean("mPrefADB", false);
    if (mPrefADB) {
        mItem.setIcon(R.drawable.ic_adb_on);
    } else {/*from w w w  . j ava  2  s . com*/
        mItem.setIcon(R.drawable.ic_adb_off);
    }
    return super.onPrepareOptionsMenu(menu);
}

From source file:gov.wa.wsdot.android.wsdot.ui.CameraImageFragment.java

private void toggleStar(MenuItem item) {
    resolver = getActivity().getContentResolver();

    if (mIsStarred) {
        item.setIcon(R.drawable.ic_menu_star);
        try {/*  www .ja v a 2 s . com*/
            ContentValues values = new ContentValues();
            values.put(Cameras.CAMERA_IS_STARRED, 0);
            resolver.update(Cameras.CONTENT_URI, values, Cameras.CAMERA_ID + "=?",
                    new String[] { Integer.toString(mId) });

            Toast.makeText(getActivity(), R.string.remove_favorite, Toast.LENGTH_SHORT).show();
            mIsStarred = false;
        } catch (Exception e) {
            Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
            Log.e("CameraImageFragment", "Error: " + e.getMessage());
        }
    } else {
        item.setIcon(R.drawable.ic_menu_star_on);
        try {
            ContentValues values = new ContentValues();
            values.put(Cameras.CAMERA_IS_STARRED, 1);
            resolver.update(Cameras.CONTENT_URI, values, Cameras.CAMERA_ID + "=?",
                    new String[] { Integer.toString(mId) });

            Toast.makeText(getActivity(), R.string.add_favorite, Toast.LENGTH_SHORT).show();
            mIsStarred = true;
        } catch (Exception e) {
            Toast.makeText(getActivity(), e.getMessage(), Toast.LENGTH_SHORT).show();
            Log.e("CameraImageFragment", "Error: " + e.getMessage());
        }
    }
}

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

@SuppressWarnings("deprecation")
@Override//from   ww w.  j  av  a  2s.  c  om
public void onPrepareOptionsMenu(Menu menu) {
    menu.clear();
    MenuItem menuItemAddNewLoanCharge = menu.add(Menu.NONE, MENU_ITEM_ADD_NEW_LOAN_CHARGES, Menu.NONE,
            getString(R.string.add_new));
    menuItemAddNewLoanCharge.setIcon(getResources().getDrawable(R.drawable.ic_action_content_new));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB)
        menuItemAddNewLoanCharge.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    super.onPrepareOptionsMenu(menu);
}

From source file:com.peppe130.fireinstaller.activities.DownloadActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {

    getMenuInflater().inflate(R.menu.activity_download_menu, menu);

    IconicsDrawable mClearDownloadsIcon = new IconicsDrawable(DownloadActivity.this)
            .icon(ControlCenter.CLEAR_DOWNLOADS_ICON).actionBar().color(Color.WHITE).sizeDp(30);

    MenuItem mClearDownloads = menu.findItem(R.id.clear_downloads);

    mClearDownloads.setIcon(mClearDownloadsIcon);

    return true;//from ww  w . j  a va  2s  .  c  o m

}

From source file:im.afterclass.android.activity.InvitePickActivity.java

/**
 * members/*from  www . ja  v a2s .c o  m*/
 * 
 * @param v
 */

public boolean onCreateOptionsMenu(Menu menu) {

    MenuItem saveItem = menu.add("saveButton");
    MenuItemCompat.setShowAsAction(saveItem, MenuItemCompat.SHOW_AS_ACTION_IF_ROOM);
    saveItem.setIcon(R.drawable.ic_action_save);
    saveItem.setOnMenuItemClickListener(new OnMenuItemClickListener() {
        @Override
        public boolean onMenuItemClick(MenuItem arg0) {

            Toast.makeText(InvitePickActivity.this, "???", Toast.LENGTH_SHORT).show();
            //Intent intent = new Intent(InvitePickActivity.this,LaunchActivity.class);
            //startActivity(intent);
            //overridePendingTransition(R.anim.head_in,0);
            return true;
        }
    });
    return true;
}

From source file:com.glabs.homegenie.fragments.GroupsViewFragment.java

public void UpdateCurrentGroupMenu() {
    StartActivity rootactivity = (StartActivity) getActivity();
    Menu menu = rootactivity.getActionMenu();
    if (menu != null) {
        MenuItem automation = menu.findItem(R.id.menu_automation);
        if (automation != null) {
            automation.setEnabled(false);
            Menu submenu = automation.getSubMenu();
            if (submenu == null)
                return;
            ////  ww  w.  j  a va 2 s .  c  o  m
            submenu.removeGroup(Menu.NONE);
            if (mGroupPrograms.size() > 0) {
                for (Module program : mGroupPrograms) {
                    MenuItem prg = submenu.add(Menu.NONE, Menu.NONE, Menu.NONE, program.getDisplayName());
                    prg.setIcon(R.drawable.ic_action_flash_on);
                    MenuCompat.setShowAsAction(prg, SHOW_AS_ACTION_IF_ROOM | SHOW_AS_ACTION_WITH_TEXT);
                    final String paddress = program.Address;
                    String groupname = "";
                    try {
                        groupname = Uri.encode(mAdapter.getGroup(mCurrentGroup).Name, "UTF-8");
                    } catch (Exception e) {
                    }
                    final String gname = groupname;
                    prg.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
                        @Override
                        public boolean onMenuItemClick(MenuItem menuItem) {
                            String apicall = "HomeAutomation.HomeGenie/Automation/Programs.Run/" + paddress
                                    + "/" + gname + "/" + new Date().getTime();
                            Control.callServiceApi(apicall, null);
                            return true;
                        }
                    });
                }
                automation.setEnabled(true);
            }
        }
        //
        //            MenuItem recordMacro = submenu.add(1, Menu.NONE, Menu.NONE, "Record macro");
        //            recordMacro.setOnMenuItemClickListener(new MenuItem.OnMenuItemClickListener() {
        //                @Override
        //                public boolean onMenuItemClick(MenuItem menuItem) {
        //                    StartActivity sa = (StartActivity)getActivity();
        //                    sa.openMacroRecordMenu();
        //                    return true;
        //                }
        //            });
        //            rootactivity.supportInvalidateOptionsMenu();
    }
}

From source file:com.drunkenhamster.facerecognitionfps.SnapFaceActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    MenuItem menu_Preference = menu.add(0, R.id.menu_Preferences, 0, R.string.menu_Preferences);
    menu_Preference.setIcon(android.R.drawable.ic_menu_preferences);
    MenuItem menu_AppMode = menu.add(0, R.id.menu_AppMode, 0, R.string.menu_AppMode);
    menu_AppMode.setIcon(android.R.drawable.ic_menu_manage);
    return true;//from w ww  . j ava 2  s .com
}

From source file:de.stadtrallye.rallyesoft.fragments.ChatroomFragment.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_COLLAPSE_ACTION_VIEW);

    MenuItem pictureMenuItem = menu.add(Menu.NONE, R.id.picture_menu, 10, R.string.take_picture);

    pictureMenuItem.setIcon(R.drawable.ic_camera_light);
    pictureMenuItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
}

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

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
    MenuItem submitItem = menu.add(Menu.NONE, R.id.submit_menu, Menu.NONE, R.string.submit_new_solution);
    submitItem.setIcon(R.drawable.ic_send_now_light);
    submitItem.setShowAsAction(MenuItem.SHOW_AS_ACTION_ALWAYS);
}

From source file:ca.rmen.android.palidamuerte.app.poem.detail.PoemDetailFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    Log.v(TAG, "onPrepareOptionsMenu");
    super.onPrepareOptionsMenu(menu);
    MenuItem fav = menu.findItem(R.id.action_favorite);
    if (fav == null) {
        Log.v(TAG, "Menu not inflated yet?");
        return;//from   ww  w . j  a v  a 2  s .  c  om
    }
    if (mIsFavorite) {
        fav.setTitle(R.string.action_favorite_activated);
        fav.setIcon(R.drawable.ic_action_favorite_activated);
    } else {
        fav.setTitle(R.string.action_favorite_normal);
        fav.setIcon(R.drawable.ic_action_favorite_normal);
    }
}