如何在Android中为imageview设置颜色 [英] How to set color for imageview in Android

查看:126
本文介绍了如何在Android中为imageview设置颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要将图标设置为 ImageView ,然后从该网站下载了图标: FlatIcon
现在我想为该图标设置颜色,但是当使用 setBackground 时,只需为背景添加颜色,而不是设置为图标!
使用 NavigationView 时,我可以使用以下代码为图标设置颜色: app:itemIconTint ="@ color/colorAccent" .

I want set icon into ImageView and i downloaded icons from this site : FlatIcon
Now i want set color to this icons but when use setBackground just add color for background and not set to icons!
When use NavigationView i can set color to icons with this code : app:itemIconTint="@color/colorAccent".

如何将图标的颜色设置到 ImageView 中,例如 itemIconTint ?谢谢所有< 3

How can i set color to icons into ImageView such as itemIconTint ? Thanks all <3

推荐答案

如果您使用的是图标,则可能会有用:

If you are using an icon maybe this can be useful:

android:tint="@color/colorAccent"

否则,您可以尝试修改类:

Otherwise you can try to modify the class:

ImageView imageViewIcon = (ImageView) listItem.findViewById(R.id.imageViewIcon);
imageViewIcon.setColorFilter(getContext().getResources().getColor(R.color.blue));

此线程中的更多信息:

More info in this thread: Is it possible to change material design icon color from xml in Android?

这篇关于如何在Android中为imageview设置颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆