Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to set icon color of MenuItem?

I defined a menu item that has ShareActionProvider and share white icon like so :

<item     android:icon="@drawable/ic_share_white_24dp"     android:id="@+id/action_share"     android:title="@string/action_share"     android:orderInCategory="200"     app:showAsAction="ifRoom"     app:actionProviderClass="android.support.v7.widget.ShareActionProvider"/> 

But when I launch the application, I get a different black share icon. How to set the share icon to be white?

Here is the result that I have

enter image description here

like image 673
Dimitri Avatar asked Aug 11 '15 23:08

Dimitri


People also ask

How do I change the color of my icon?

One way to quickly change app icon colors is to use Themed icons. But there's a catch: Not every icon will change—only Google-provided ones like Chrome, YouTube, Camera, Phone, Messages, Play Store, Gmail, etc. Go to Settings > Wallpaper & style > Themed icons and select what you'd like to use.

How to set icon color in menu item in android?

add app:iconTint="@color/yourcolor" in your MenuItem for change the Icon color.


1 Answers

The icon is actually provided by the ShareActionProvider and you can't change it afaik. You can, however, customize the color by setting the textColorPrimary in your styles.xml:

<android.support.v7.widget.Toolbar     android:id="@+id/toolbar"     android:layout_width="match_parent"     android:layout_height="?attr/actionBarSize"     app:theme="@style/MyActionBarTheme"     app:popupTheme="@style/ThemeOverlay.AppCompat.Light"> 

<style name="MyActionBarTheme" parent="ThemeOverlay.AppCompat.Dark.ActionBar">     <item name="android:textColorPrimary">#fa0</item> </style> 

For any custom icons, you would have to color them yourself, ie.

@Override public boolean onCreateOptionsMenu(Menu menu) {     getMenuInflater().inflate(R.menu.menu_main, menu);      for(int i = 0; i < menu.size(); i++){         Drawable drawable = menu.getItem(i).getIcon();         if(drawable != null) {             drawable.mutate();             drawable.setColorFilter(getResources().getColor(R.color.textColorPrimary), PorterDuff.Mode.SRC_ATOP);         }     }      return true; } 
like image 92
tachyonflux Avatar answered Sep 28 '22 10:09

tachyonflux