android change icon color

Sometimes ui gives us the color of an icon, but we need another color, this time we can change the color of the icon through code

Use imageview.setcolorFilter(int color) to achieve the effect, but there are a few points to note:

1. The icon set by imageview must be set by setImageResource, if it is set by backgroundresource, it is invalid

2. The parameter color must be the system default color, that is, the int constant in Color, such as Color.GRAY, Color.RED, if R.color.xxx is used, it is invalid


Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325624372&siteId=291194637