5

I've created a menu with a single item.

<menu xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto">
    <item
        android:id="@+id/syncButton"
        android:title="Sync"
        android:icon="@drawable/ic_sub_menu"
        app:showAsAction="never"/>
</menu>

This is used on some of my activities in the toolbar, when clicked it drops down a menu, currently there is only one option but in the future it may be more.

Everything works well except the icon, it's a vector image of the traditional 3 dots colored white. Depending on what showAsAction" is set as it changes color.

Currently showAsAction is set to never so it displays a menu when clicked, this is what I want, but the icon changes to a dark grey. If i set this option to "always" then the icon changes to white but I lose the drop down menu.

How can I keep the drop down menu while keeping my icon white ?

4
  • try this stackoverflow.com/questions/19882443/…
    – Ankita
    Jul 4, 2018 at 7:38
  • basically you want to change the 3dots icon to 3whiteDots?
    – Aiko West
    Jul 4, 2018 at 7:39
  • The toolbar displays the 3 dots icon colored grey by default to indicate where you click to drop the menu. So you added in your menu an item that has an icon with 3 dots?
    – user8959091
    Jul 4, 2018 at 7:42
  • So you're saying that the grey is the default when there is a drop down menu and is overriding my icon that I've set, I didn't know it did that. Thank you
    – Demonic218
    Jul 4, 2018 at 8:05

2 Answers 2

3

If you just want to change the 3-Dots-Icon for the DropDownMenu, you can change this in your Styles.xml:

In your Theme Style define

<item name="android:actionOverflowButtonStyle">@style/MyTheme.OverFlow</item>

and then define the Overflow with your Icon you want to show instead the 3DotsIcon (in your case the Icon with 3 white dots)

  <style name="MyTheme.OverFlow">
    <item name="android:src">@drawable/yourNewIcon</item>
  </style>
0
3

Try this code

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater menuInflater) {
    menuInflater.inflate(R.menu.menu_confirm, menu);
    MenuItem action_done = menu.findItem(R.id.action_done);
    action_done.setIcon(R.drawable.ic_filter);
    menuIconColor(action_done, Color.WHITE);
    super.onCreateOptionsMenu(menu, menuInflater);
}

public void menuIconColor(MenuItem menuItem, int color) {
    Drawable drawable = menuItem.getIcon();
    if (drawable != null) {
        drawable.mutate();
        drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
    }
}

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.