Is it possible to change material design icon colo

2019-01-13 20:42发布

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?

10条回答
beautiful°
2楼-- · 2019-01-13 21:02

I was looking for the same thing but to change it dynamically in the code. I hope this helps someone looking for the same thing.

Create an ImageView for the icon and use setColorFilter on that view.

ImageView imageViewIcon = (ImageView) listItem.findViewById(R.id.imageViewIcon);
imageViewIcon.setColorFilter(getContext().getResources().getColor(R.color.blue));
查看更多
该账号已被封号
3楼-- · 2019-01-13 21:04

How to change material icon color in XML

<ImageButton 
     android:layout_width="YourValue"
     android:layout_height="YourValue"
     ...
     android:tint="YourColor" // this line do the magic
/>
查看更多
Deceive 欺骗
4楼-- · 2019-01-13 21:09

Yes, it's possible and it's simple using this library: https://github.com/jrvansuita/IconHandler

You can easily call this:

Icon.on(yourImageView).color(R.color.your_color).icon(R.mipmap.your_icon).put();
查看更多
爷的心禁止访问
5楼-- · 2019-01-13 21:09

As the icon file is in .png format, you should change the color using the tool from which you've created icon. and add it using ImageAsset into project .

查看更多
时光不老,我们不散
6楼-- · 2019-01-13 21:15

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.

查看更多
祖国的老花朵
7楼-- · 2019-01-13 21:15
<vector android:height="48dp" android:viewportHeight="24.0"
    android:viewportWidth="24.0" android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
    <path android:fillColor="#ca0f0f" android:pathData="M3,5v14c0,1.1 0.89,2 2,2h14c1.1,0 2,-0.9 2,-2V5c0,-1.1 -0.9,-2 -2,-2H5c-1.11,0 -2,0.9 -2,2zm12,4c0,1.66 -1.34,3 -3,3s-3,-1.34 -3,-3 1.34,-3 3,-3 3,1.34 3,3zm-9,8c0,-2 4,-3.1 6,-3.1s6,1.1 6,3.1v1H6v-1z"/>
</vector>

you change color by changing android:fillColor="#ca0f0f"

查看更多
登录 后发表回答