Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to change material design icon color from xml in Android?

I'm actually trying to use colored icons in my app. I've downloaded the official material design icon pack from here. Now all the icons in this pack are either white, grey or black. But I want the icons to be of a different color. Something like the icons on the left side in this image. The phone phone and mail icons are blue. How can I accomplish this?

like image 893
Akshay Avatar asked Apr 22 '15 07:04

Akshay


People also ask

How do I change the color of my material icon?

If you want to use Jquery$(". material-icons"). css("color", themeColor); This will change color of the material icons inside an element eg input field.

Can you change the color of icons on Android?

Search for and select Open App, and then, on the New Shortcut page, tap Choose. Locate the app whose appearance you want to change. Back on the New Shortcut page, you'll see the app name; tap More (three dots), change the app's name, tap its icon, select Color, and choose a new color.

How do I change the color of a drawable in xml?

Use app:drawableTint="@color/yourColor" in the xml instade android:drawableTint="@color/yourColor" . It has the backward compatibility.

What is xml color?

A color value defined in XML. The color is specified with an RGB value and alpha channel. You can use a color resource any place that accepts a hexadecimal color value. You can also use a color resource when a drawable resource is expected in XML (for example, android:drawable="@color/green" ).


2 Answers

For changing icon color try

<ImageButton     android:layout_width="your value"     android:layout_height="your value"     /* and so on ... */      android:tint="YourColor"     /> 

Note: the tint color is painted ontop of the image, not a replacement color. So tint #80ff0000 on a black image gives you 50 % red on black, not 50 % red on the background. I.e. this is not equivalent to iOS template images.

like image 84
Yogesh Borkhade Avatar answered Sep 19 '22 19:09

Yogesh Borkhade


You can use the TintImageView within the appcompat support library and then tinting/coloring the imageview is by simply calling the android:backgroundTint to tint the imageview into one color.


Xml

<TintImageView android:layout_width="" android:layout_height=""  android:src="" android:backgroundTint="@color/green"/> 

or

<ImageView  android:tint="the_color_you_want"/> 

Programatically

ImageView yourImageView = findViewById(...) yourImageView.setColorFilter(Context.getColor(your_color_here))


So the above xml will tint the imageView to color green, means that it will colorize each pixel of the imageview that are visible to green.

like image 37
Rod_Algonquin Avatar answered Sep 21 '22 19:09

Rod_Algonquin