How to change icon colors in android studio
Asked Answered
T

10

34

I downloaded some icons from material.io but they only offer the icons in black. I saw a youtube video where they use to allow you to choose the color. Anyway, I am trying to change the colors of the icons to white. I am not having any luck. I tried to change the fill color in android studio but it doesn't work. Any assistance would be appreciated such as exact code and files to add the code to. Thanks.

Tiffie answered 31/3, 2017 at 13:33 Comment(0)
J
30

You can directly download these images in Android Studio.

res > right click > New > Image Asset and select

  • Icon Type : Action Bar and Tab Icones
  • Asset Type : Clip Art
  • Theme : CUSTOM

And you can select any clip art that you want, select the color, padding, etc ...

enter image description here

Jareb answered 31/3, 2017 at 13:59 Comment(0)
P
85

simply you can use

android:tint="@android:color/white"

Plat answered 19/12, 2017 at 11:6 Comment(1)
This should be the accepted answer since it allows developers to change the color of any existing icon, instead of just creating a new one.Mukden
J
30

You can directly download these images in Android Studio.

res > right click > New > Image Asset and select

  • Icon Type : Action Bar and Tab Icones
  • Asset Type : Clip Art
  • Theme : CUSTOM

And you can select any clip art that you want, select the color, padding, etc ...

enter image description here

Jareb answered 31/3, 2017 at 13:59 Comment(0)
F
11

As mentioned before, the material.io icons can be downloaded directly with Android Studio. This solution shows the importing of vector asset icons which are easier to manage since they are stored in a single location (res/drawable) vs. image assets that will have each icon stored in specific density folders (hdpi, xhdpi, etc).

  1. expand the "res" folder
  2. right click drawable
  3. hover over "new"
  4. select "Vector Asset"

Creating Vector Icon

  1. click the image next to "icon"
  2. select desired material.io icon
  3. Name the icon what you would like
  4. select "next"

Now you will have two options of setting the icon color

  1. In the layout by using the android:tint attribute of an ImageView. This is my preference because the icon can be viewed prior to runtime.

Layout Icon Color Change Example

or

  1. In Java.

imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white), PorterDuff.Mode.MULTIPLY);

Fezzan answered 20/6, 2017 at 14:28 Comment(0)
T
4

https://material.io/icons/ actually does let you download icons in white.

enter image description here

But, depending on what exactly you want to do, there are a few options. If you simply want white icons (and not to change them at runtime), you may find this plugin for Android Studio useful: https://github.com/konifar/android-material-design-icon-generator-plugin

It allows you to generate the material design icons right in Android Studio, in whatever color you want. Another alternative for downloading these icons in different colors is https://materialdesignicons.com/.

If you do want to color the icons at runtime, try something like this:

imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white), 
        PorterDuff.Mode.MULTIPLY);
Temblor answered 31/3, 2017 at 13:47 Comment(0)
O
0

You can download white icons from material.io. also look at themes and theme overlays

Material white

Oralla answered 31/3, 2017 at 13:53 Comment(0)
I
0

Instead of android:src

I use attribute android:foreground

android:foreground="@drawable/ic_add"
Intoxication answered 15/3, 2022 at 3:47 Comment(0)
E
0

For those not getting what they want yet try changing the PorterDuff mode, the following is what did it for me

imageView.setColorFilter(ContextCompat.getColor(context, android.R.color.white), 
    PorterDuff.Mode.SRC_ATOP);
Edraedrea answered 25/3, 2022 at 11:42 Comment(0)
P
0

maybe app:iconTint help you, I am writing this because of the following reference. Material Design 3

Polygon answered 11/8, 2022 at 15:49 Comment(0)
A
0

With Android Compose, you can try :

Icon(
  painter = painterResource(id = iconId),
  contentDescription = null,
  modifier = Modifier.size(28.dp),
  tint = MaterialTheme.colorScheme.secondary // set the color of your choice
)

Amalea answered 23/4, 2023 at 6:19 Comment(0)
D
0

As of 2023, Nouman's answer isn't working, at least with icons on buttons. Since this question appears first in relevant google searches, here's an update:

The correct way to set the color of an icon inside a button (and not create a new one) is with:

app:iconTint="@color/white"
Dike answered 19/7, 2023 at 10:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.