I have a toolbar to which I added a list with a menu.

<?xml version="1.0" encoding="utf-8"?> 

 <!--Action buttons --> <item android:id="@+id/toolbar_attach" android:icon="@drawable/ic_action_attachment_2" android:orderInCategory="0" android:title="@string/attach" app:showAsAction="always" /> <item android:id="@+id/toolbar_record" android:icon="@drawable/ic_action_mic" android:orderInCategory="1" android:title="@string/record" app:showAsAction="always" /> <!--Popup menu--> <item android:id="@+id/toolbar_save" android:orderInCategory="0" android:title="@string/save" app:showAsAction="never" /> <item android:id="@+id/toolbar_cancel" android:orderInCategory="1" android:title="@string/cancel" app:showAsAction="never" /> <item android:id="@+id/toolbar_delete" android:orderInCategory="2" android:title="@string/delete" app:showAsAction="never" /> 

The problem is that the color of the toolbar is dark and the icons on it are lost (labeled showAsAction). Therefore, I want to change their color, for example, to white.

picture

I looked for options, tried android: iconTint = "desired_color", but this solution is suitable for api 26+. Tell me the solution.

    2 answers 2

    You can do it programmatically like this :

     @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; } 

      For earlier versions of the API, you can change the color of the icons themselves . In the drawable folder, find the desired icon, open and instead of black (by default) specify the desired color.

       <path android:fillColor="@color/blue" android:pathData="..."/> 

      It is also worth noting that you can change the color only for vector icons. If for some reason you are using a raster , then the color of such icons can be changed only in a graphic editor.

      • A good solution, but in my case icons are not vector, but raster. Thanks for the answer. - Evgeny Vasilyev
      • So for the raster you can change the color. Use Vector Asset to add vector icons. Judging by the screen they are standard. - kulikovman
      • @YevgenyVasilyev, you are sure that your icons are raster. Judging by the @drawable/ic_action_mic this looks like a vector. - kulikovman
      • If I'm not mistaken, then the .png format is not intended for vector images, and my icons have exactly this format. - Evgeny Vasilyev
      • @YevgenyVasilyev, you are right, png is not a vector. It's just strange that they are in the drawable folder. Corrected the answer. - kulikovman