Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Menu item icon changes color

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 ?

like image 493
Demonic218 Avatar asked Jul 04 '18 07:07

Demonic218


People also ask

How do I change the background color of my menu?

How To Change Menu Background Color in WordPress. 1 Step 1: Find the CSS ID. The first step to editing the styles for the menu is finding the CSS ID codes for your theme’s menu and header. To do this, ... 2 Step 2: Define Menu Background Colors. 3 Step 3: Change Menu Link Color. 4 Step 4: Change Mobile Menu Background Color.

How to change the text color of the menu item in Android?

How to change the text color of Menu item in Android? This example demonstrates how do I change the text color of the menu item in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main.xml.

Can I change the color of my WordPress menu design?

Most WordPress themes don’t provide you with the option to edit the colors used in the menu. And sometimes, it can ruin the branding of your entire website design. Thankfully, there’s a way you can edit the menu design and change its color. In this post, we’ll show you how to do just that in a few easy steps.

How to change the color of an icon in Actionbar?

add app:iconTint="@color/yourcolor" in your MenuItem for change the Icon color. Show activity on this post. This is a theming issue. Depending on your current theme, you need to set the correct ActionBar overlay theme. The Action Provider reads a value in the theme (which indicates if the theme is dark or light) to determine the color of the icon.


2 Answers

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>
like image 93
Aiko West Avatar answered Oct 03 '22 07:10

Aiko West


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);
    }
}
like image 36
Hardik Vasani Avatar answered Oct 03 '22 08:10

Hardik Vasani