Example usage for android.view MenuItem getIcon

List of usage examples for android.view MenuItem getIcon

Introduction

In this page you can find the example usage for android.view MenuItem getIcon.

Prototype

public Drawable getIcon();

Source Link

Document

Returns the icon for this item as a Drawable (getting it from resources if it hasn't been loaded before).

Usage

From source file:despotoski.nikola.github.com.bottomnavigationlayout.BottomTabLayout.java

private void populateFromMenuResource(@NonNull MenuBuilder menuBuilder) {
    removeAllTabs();// w w w . ja v a2 s . c o  m
    int size = menuBuilder.size();
    checkBottomItemGuidelines(size);
    for (int i = 0; i < size; i++) {
        MenuItem item = menuBuilder.getItem(i);
        BottomNavigationItem bottomNavigationItem = BottomNavigationItemBuilder.create(item.getIcon(),
                String.valueOf(item.getTitle()), getParentBackgroundColor(i));
        bottomNavigationItem.setPosition(i);
        addBottomNavigationItem(bottomNavigationItem);
    }
    updateBottomNavViews();
}

From source file:com.terracom.mumbleclient.app.QRPushToTalkActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem disconnectButton = menu.findItem(R.id.action_disconnect);
    try {/*from  ww w .  j a  va 2 s  . co m*/
        disconnectButton.setVisible(mService != null && mService.isConnected());
    } catch (RemoteException e) {
        e.printStackTrace();
    }

    // Color the action bar icons to the primary text color of the theme.
    int foregroundColor = getSupportActionBar().getThemedContext()
            .obtainStyledAttributes(new int[] { android.R.attr.textColor }).getColor(0, -1);
    for (int x = 0; x < menu.size(); x++) {
        MenuItem item = menu.getItem(x);
        if (item.getIcon() != null) {
            Drawable icon = item.getIcon().mutate(); // Mutate the icon so that the color filter is exclusive to the action bar
            icon.setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
        }
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.morlunk.mumbleclient.app.PlumbleActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem disconnectButton = menu.findItem(R.id.action_disconnect);
    disconnectButton.setVisible(mService != null && mService.isSynchronized());

    // Color the action bar icons to the primary text color of the theme.
    int foregroundColor = getSupportActionBar().getThemedContext()
            .obtainStyledAttributes(new int[] { android.R.attr.textColor }).getColor(0, -1);
    for (int x = 0; x < menu.size(); x++) {
        MenuItem item = menu.getItem(x);
        if (item.getIcon() != null) {
            Drawable icon = item.getIcon().mutate(); // Mutate the icon so that the color filter is exclusive to the action bar
            icon.setColorFilter(foregroundColor, PorterDuff.Mode.MULTIPLY);
        }// ww  w . j  av a 2 s.c o m
    }

    return super.onPrepareOptionsMenu(menu);
}

From source file:com.dwdesign.tweetings.fragment.BaseStatusesListFragment.java

public void openMenu(View view, ParcelableStatus status) {
    mPopupMenu = PopupMenu.getInstance(getActivity(), view);
    mPopupMenu.inflate(R.menu.action_status);
    final int activated_color = getResources().getColor(R.color.holo_blue_bright);
    final boolean click_to_open_menu = mPreferences.getBoolean(PREFERENCE_KEY_CLICK_TO_OPEN_MENU, false);
    final String buffer_authorised = mPreferences.getString(PREFERENCE_KEY_BUFFERAPP_ACCESS_TOKEN, null);
    final Menu menu = mPopupMenu.getMenu();
    final MenuItem itemView = menu.findItem(MENU_VIEW);
    if (itemView != null) {
        itemView.setVisible(click_to_open_menu);
    }//from  www.j  a  v  a 2 s .c  om
    final MenuItem direct_retweet = menu.findItem(MENU_RETWEET);
    if (direct_retweet != null) {
        final Drawable icon = direct_retweet.getIcon().mutate();
        direct_retweet.setVisible(
                (!status.is_protected && status.account_id != status.user_id) || isMyRetweet(status));
        if (isMyRetweet(status)) {
            icon.setColorFilter(activated_color, PorterDuff.Mode.MULTIPLY);
            direct_retweet.setTitle(R.string.cancel_retweet);
        } else {
            icon.clearColorFilter();
            direct_retweet.setTitle(R.string.retweet);
        }
    }
    final MenuItem bufferView = menu.findItem(MENU_ADD_TO_BUFFER);
    if (bufferView != null) {
        if (buffer_authorised != null && !buffer_authorised.equals("")) {
            bufferView.setVisible(true);
        } else {
            bufferView.setVisible(false);
        }
    }
    setMenuForStatus(getActivity(), menu, status);
    mPopupMenu.setOnMenuItemClickListener(this);
    mPopupMenu.show();
}

From source file:com.lemon.lime.MainActivity.java

@Override
public boolean onPrepareOptionsMenu(Menu menu) {
    MenuItem back = menu.findItem(R.id.back);
    MenuItem forward = menu.findItem(R.id.forward);
    if (mWebView.canGoBack()) {
        back.setEnabled(true);/*w  w w.java  2  s. c  om*/
        back.getIcon().setAlpha(255);
    } else {
        // disabled
        back.setEnabled(false);
        back.getIcon().setAlpha(130);
    }
    if (mWebView.canGoForward()) {
        forward.setEnabled(true);
        forward.getIcon().setAlpha(255);
    } else {
        // disabled
        forward.setEnabled(false);
        forward.getIcon().setAlpha(130);
    }
    return true;
}

From source file:com.android.contacts.activities.ContactSelectionActivity.java

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

    final MenuInflater inflater = getMenuInflater();
    inflater.inflate(R.menu.search_menu, menu);

    final MenuItem searchItem = menu.findItem(R.id.menu_search);
    searchItem.setVisible(!mIsSearchMode && mIsSearchSupported);

    final Drawable searchIcon = searchItem.getIcon();
    if (searchIcon != null) {
        searchIcon.mutate().setColorFilter(ContextCompat.getColor(this, R.color.actionbar_icon_color),
                PorterDuff.Mode.SRC_ATOP);
    }//  w ww.  j  a  va 2 s .  com
    return true;
}

From source file:com.jecelyin.editor.v2.ui.MainActivity.java

/**
 *
 * @param menuResId/*from w w  w . j a  va2 s . c  om*/
 * @param status {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_NORMAL}, {@link com.jecelyin.editor.v2.view.menu.MenuDef#STATUS_DISABLED}
 */
public void setMenuStatus(@IdRes int menuResId, int status) {
    MenuItem menuItem = mToolbar.getMenu().findItem(menuResId);
    if (menuItem == null) {
        throw new RuntimeException("Can't find a menu item");
    }
    Drawable icon = menuItem.getIcon();
    if (status == MenuDef.STATUS_DISABLED) {
        menuItem.setEnabled(false);
        menuItem.setIcon(MenuManager.makeToolbarDisabledIcon(icon));
    } else {
        menuItem.setEnabled(true);
        if (menuItem.getGroupId() == MenuDef.GROUP_TOOLBAR) {
            menuItem.setIcon(MenuManager.makeToolbarNormalIcon(icon));
        } else {
            menuItem.setIcon(MenuManager.makeMenuNormalIcon(icon));
        }
    }
}

From source file:com.ayuget.redface.ui.activity.ReplyActivity.java

private void styleToolbarMenu(Toolbar toolbar) {
    for (int i = 0; i < toolbar.getMenu().size(); i++) {
        MenuItem menuItem = toolbar.getMenu().getItem(i);
        Drawable itemIcon = menuItem.getIcon();

        if (itemIcon != null) {
            UiUtils.setDrawableColor(itemIcon, UiUtils.getReplyToolbarIconsColor(ReplyActivity.this));
        }//from w w  w  .  j  a  v  a  2s . c  o m
    }
}

From source file:net.gsantner.opoc.util.ContextUtils.java

/**
 * Try to tint all {@link Menu}s {@link MenuItem}s with given color
 *//*w  w  w. j a v  a  2 s . com*/
@SuppressWarnings("ConstantConditions")
public void tintMenuItems(Menu menu, boolean recurse, @ColorInt int iconColor) {
    for (int i = 0; i < menu.size(); i++) {
        MenuItem item = menu.getItem(i);
        try {
            tintDrawable(item.getIcon(), iconColor);
            if (item.hasSubMenu() && recurse) {
                tintMenuItems(item.getSubMenu(), recurse, iconColor);
            }
        } catch (Exception ignored) {
            // This should not happen at all, but may in bad menu.xml configuration
        }
    }
}

From source file:de.bahnhoefe.deutschlands.bahnhofsfotos.DetailsActivity.java

private void enableMenuItem(Menu menu, int id) {
    MenuItem menuItem = menu.findItem(id).setEnabled(true);
    menuItem.getIcon().mutate();
    menuItem.getIcon().setColorFilter(WHITE, PorterDuff.Mode.SRC_ATOP);
}