如何在Android中为imageview设置颜色

如何在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?