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:net.lp.actionbarpoirot.actions.UiAction.java

/**
 * Add the {@link UiAction} to the native action bar.
 * //from ww  w. ja  va  2  s.  c o  m
 * Call this method selectively from {@link onCreateOptionsMenu()}.
 * 
 * @param menuItem
 * @param context
 *            The {@link Activity} context.
 */
@TargetApi(Build.VERSION_CODES.HONEYCOMB)
protected void onCreateOptionsMenuMoreNative(MenuItem menuItem, C context) {
    menuItem.setShowAsAction(showActionEnum);
    menuItem.setIcon(getActionBarIcon());
}

From source file:org.dharmaseed.android.PlayTalkActivity.java

@Override
public boolean onPrepareOptionsMenu(final Menu menu) {
    MenuItem star = menu.findItem(R.id.play_talk_action_toggle_starred);
    if (dbManager.isStarred(DBManager.C.TalkStars.TABLE_NAME, talkID)) {
        star.setIcon(ContextCompat.getDrawable(this,
                getResources().getIdentifier("btn_star_big_on", "drawable", "android")));
    } else {//from  w w w  .  j ava  2s.co m
        star.setIcon(ContextCompat.getDrawable(this,
                getResources().getIdentifier("btn_star_big_off", "drawable", "android")));
    }
    return true;
}

From source file:tv.acfun.video.DetailsActivity.java

@Override
public boolean onCreateOptionsMenu(final Menu menu) {
    getMenuInflater().inflate(R.menu.details, menu);
    if (mCookies != null)
        new Thread() {
            public void run() {
                isFaved = MemberUtils.checkFavourite(API.getDomainRoot(getApplicationContext()), mCookies,
                        mAcId);/*w  ww  .  j a v  a2  s  .c  o m*/
                if (isFaved) {
                    runOnUiThread(new Runnable() {
                        @Override
                        public void run() {
                            MenuItem item = menu.findItem(R.id.action_fav);
                            item.setTitle("??");
                            item.setIcon(R.drawable.ic_action_favorited);
                        }
                    });
                }
            }
        }.start();
    mShareMenuItem = menu.findItem(R.id.action_share);
    if (mVideo != null)
        mShareMenuItem.setEnabled(true);
    getMenuInflater().inflate(R.menu.main, menu);
    return super.onCreateOptionsMenu(menu);
}

From source file:uk.ac.horizon.artcodes.activity.NavigationActivity.java

private void updateAccounts() {
    final Menu menu = binding.navigation.getMenu();
    final MenuItem libraries = menu.findItem(R.id.nav_libraries);
    final SubMenu subMenu = libraries.getSubMenu();

    while (subMenu.size() > 0) {
        subMenu.removeItem(subMenu.getItem(0).getItemId());
    }/*from  ww  w  .  j a v a  2  s . com*/

    final List<Account> accounts = getServer().getAccounts();
    for (int index = 0; index < accounts.size(); index++) {
        final Account account = accounts.get(index);
        final MenuItem menuItem = subMenu.add(R.id.navigation, index, Menu.NONE, account.getDisplayName());
        if (account.getId().equals("local")) {
            menuItem.setIcon(R.drawable.ic_folder_24dp);
        } else {
            menuItem.setIcon(R.drawable.ic_cloud_24dp);
        }
        menuItem.setCheckable(true);
    }

    final MenuItem menuItem = subMenu.add(R.id.navigation, R.id.nav_addaccount, Menu.NONE,
            R.string.nav_addaccount);
    menuItem.setIcon(R.drawable.ic_add_24dp);

    for (int i = 0, count = binding.navigation.getChildCount(); i < count; i++) {
        final View child = binding.navigation.getChildAt(i);
        if (child != null && child instanceof ListView) {
            final ListView menuView = (ListView) child;
            final HeaderViewListAdapter adapter = (HeaderViewListAdapter) menuView.getAdapter();
            final BaseAdapter wrapped = (BaseAdapter) adapter.getWrappedAdapter();
            wrapped.notifyDataSetChanged();
        }
    }

    getServer().loadRecent(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem recent = menu.findItem(R.id.nav_recent);
            if (recent != null) {
                recent.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
    getServer().loadStarred(new LoadCallback<List<String>>() {
        @Override
        public void loaded(List<String> item) {
            final MenuItem starred = menu.findItem(R.id.nav_starred);
            if (starred != null) {
                starred.setVisible(!item.isEmpty());
            }
        }

        @Override
        public void error(Throwable e) {
            GoogleAnalytics.trackException(e);
        }
    });
}

From source file:com.darshancomputing.BatteryIndicator.CurrentInfoFragment.java

@Override
public void onPrepareOptionsMenu(Menu menu) {
    MenuItem snItem = menu.findItem(R.id.menu_show_notification);
    MenuItem closeItem = menu.findItem(R.id.menu_close);

    if (activity.sp_store.getBoolean(BatteryInfoService.KEY_SHOW_NOTIFICATION, true)) {
        snItem.setIcon(R.drawable.ic_menu_stop);
        snItem.setTitle(R.string.menu_hide_notification);
    } else {//from   www  .j a va2  s  . c  o  m
        snItem.setIcon(R.drawable.ic_menu_notifications);
        snItem.setTitle(R.string.menu_show_notification);
    }

    if (serviceCloseable)
        closeItem.setEnabled(true);
    else
        closeItem.setEnabled(false);
}

From source file:com.glanznig.beepme.view.MainActivity.java

@Override
public boolean onOptionsItemSelected(MenuItem item) {
    BeeperApp app = (BeeperApp) getApplication();

    switch (item.getItemId()) {
    case R.id.action_toggle_beeper:
        if (app.isBeeperActive()) {
            app.cancelTimer(); //call before setBeeperActive
            app.setBeeperActive(BeeperApp.BEEPER_INACTIVE);
            item.setIcon(R.drawable.ic_menu_beeper_off);

            // hide generate beep menu entry
            if (this.actionMenu != null && app.getPreferences().isTestMode()) {
                MenuItem testBeep = actionMenu.findItem(R.id.action_test_beep);
                testBeep.setVisible(false);
            }// w  ww.  j a  v  a2s  . c  o m
        } else {
            app.setBeeperActive(BeeperApp.BEEPER_ACTIVE);
            app.setTimer();
            item.setIcon(R.drawable.ic_menu_beeper_on);

            // show generate beep menu entry
            if (this.actionMenu != null && app.getPreferences().isTestMode()) {
                MenuItem testBeep = actionMenu.findItem(R.id.action_test_beep);
                testBeep.setVisible(true);
            }
        }

        return true;

    case R.id.action_test_beep:
        app.beep();
        return true;

    case R.id.action_export:
        Intent iExport = new Intent(this, ExportActivity.class);
        startActivity(iExport);
        return true;

    case R.id.action_settings:
        Intent iSettings = new Intent(this, SettingsActivity.class);
        startActivity(iSettings);
        return true;

    case R.id.action_about:

        // thanks to F-Droid for the inspiration
        View view = null;
        LayoutInflater inflater = LayoutInflater.from(this);
        view = inflater.inflate(R.layout.about, null);

        try {
            PackageInfo pkgInfo = getPackageManager().getPackageInfo(getApplicationContext().getPackageName(),
                    0);
            ((TextView) view.findViewById(R.id.about_version)).setText(pkgInfo.versionName);
        } catch (Exception e) {
        }

        AlertDialog.Builder alertBuilder = null;
        alertBuilder = new AlertDialog.Builder(this).setView(view);

        AlertDialog dia = alertBuilder.create();
        dia.setIcon(R.drawable.ic_launcher_beepme);
        dia.setTitle(getString(R.string.about_title));
        dia.setButton(AlertDialog.BUTTON_NEUTRAL, getString(R.string.about_donate_button),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                        Uri uri = Uri.parse("http://beepme.yourexp.at/support-beepme");
                        startActivity(new Intent(Intent.ACTION_VIEW, uri));
                    }
                });

        dia.setButton(AlertDialog.BUTTON_NEGATIVE, getString(android.R.string.ok),
                new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int whichButton) {
                    }
                });
        dia.show();
        return true;
    }
    return super.onOptionsItemSelected(item);
}

From source file:com.android.calendar.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search_title_bar, menu);

    // replace the default top layer drawable of the today icon with a custom drawable
    // that shows the day of the month of today
    MenuItem menuItem = menu.findItem(R.id.action_today);
    if (Utils.isJellybeanOrLater()) {
        LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
        Utils.setTodayIcon(icon, this, Utils.getTimeZone(SearchActivity.this, mTimeChangesUpdater));
    } else {// w ww.j  a  v  a2s .  com
        menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light);
    }

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

    MenuItemCompat.expandActionView(item);
    MenuItemCompat.setOnActionExpandListener(item, this);
    mSearchView = (SearchView) MenuItemCompat.getActionView(item);
    Utils.setUpSearchView(mSearchView, this);
    mSearchView.setQuery(mQuery, false);
    mSearchView.clearFocus();

    return true;
}

From source file:com.android.gallery3d2.ingest.IngestActivity.java

private void setSwitcherMenuState(MenuItem menuItem, boolean inFullscreenMode) {
    if (menuItem == null)
        return;/*from  ww w .j  a v a  2 s  . c om*/
    if (!inFullscreenMode) {
        menuItem.setIcon(android.R.drawable.ic_menu_zoom);
        menuItem.setTitle(R.string.switch_photo_fullscreen);
    } else {
        menuItem.setIcon(android.R.drawable.ic_dialog_dialer);
        menuItem.setTitle(R.string.switch_photo_grid);
    }
}

From source file:com.hybris.mobile.activity.StoreLocatorDetailActivity.java

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

    MenuItem geofenceItem = menu.findItem(R.id.geofence_store);

    // We display an active icon if there is a geofence for this store AND the geofencing functionnality is activated
    if (geofenceJsonSharedPreferences.getGeofenceObject(store.getName()) != null
            && Hybris.isGeofencingActivated()) {
        geofenceItem.setIcon(R.drawable.ic_menu_location_active);
    }//from   ww  w  .ja  v a2 s .  c o m
    // Otherwise we display the default icon
    else {
        geofenceItem.setIcon(R.drawable.ic_menu_location_default);
    }

    return true;
}

From source file:com.xandy.calendar.SearchActivity.java

@Override
public boolean onCreateOptionsMenu(Menu menu) {
    super.onCreateOptionsMenu(menu);
    getMenuInflater().inflate(R.menu.search_title_bar, menu);

    // replace the default top layer drawable of the today icon with a custom drawable
    // that shows the day of the month of today
    MenuItem menuItem = menu.findItem(R.id.action_today);
    if (Utils.isJellybeanOrLater()) {
        LayerDrawable icon = (LayerDrawable) menuItem.getIcon();
        Utils.setTodayIcon(icon, this, Utils.getTimeZone(SearchActivity.this, mTimeChangesUpdater));
    } else {//from w  ww.  j a  va 2 s.  co m
        menuItem.setIcon(R.drawable.ic_menu_today_no_date_holo_light);
    }

    MenuItem item = menu.findItem(R.id.action_search);
    item.expandActionView();
    item.setOnActionExpandListener(this);
    mSearchView = (SearchView) item.getActionView();
    Utils.setUpSearchView(mSearchView, this);
    mSearchView.setQuery(mQuery, false);
    mSearchView.clearFocus();

    return true;
}