Change the color of material icons?

I have downloaded several material icons here:

https://material.io/icons/

I am confused by the way I change the color of these icons as drawables. I have a Button with an icon in the drawableLeft property, and then next to the ImageButton with the icons set:

 <Button android:text="Hey" android:layout_width="wrap_content" android:layout_height="wrap_content" android:drawableLeft="@drawable/ic_arrow_upward_black_24dp" android:stateListAnimator="@null" /> <ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" app:srcCompat="@drawable/ic_arrow_downward_black_24dp" android:background="@null" /> 

How to change the color of the icons for each?

Also, if the icons that I downloaded are black, how can I change the color of the icons to a color with transparency?

+5
source share
5 answers

You implement All material icons at https://material.io/icons/ are now available in Android Studio , You do not even need to download them. Just right click on the drawings> New> Vector Resource

A dialog like

<w640 "

After clicking the small Android icon, select an image and save it. This will create an xml drawable that you can open and edit as you wish.

This is how it will look

 <vector xmlns:android="http://schemas.android.com/apk/res/android" android:alpha="0.8" <!--set the transparency from here --> android:width="24dp" android:height="24dp" android:viewportWidth="24.0" android:viewportHeight="24.0"> <path android:fillColor="#FF000000" <!-- Use this for setting your color --> android:pathData="M9.4,16.6L4.8,12l4.6,-4.6L8,6l-6,6 6,6 1.4,-1.4zM14.6,16.6l4.6,-4.6 -4.6,-4.6L16,6l6,6 -6,6 -1.4,-1.4z"/> </vector> 
+21
source

Add this to your ImageButton in your xml layout file

 android:tint="@color/black" android:tintMode="@color/black" 
+4
source

If your icons are vectors, you can edit the xml file and change the android:fillColor . If the icons are bitmap images, you can add the android:tint attribute to ImageButton.

+1
source

All appcompat widgets support the android:tint="@color/somecolorresource" attribute android:tint="@color/somecolorresource" . If your activity / fragment expands with AppCompatActivity/Fragment , this will work for any ImageView/TextView/ImageButton/...

See: fooobar.com/questions/108888 / ...

0
source

Source: https://habr.com/ru/post/1262384/


All Articles