为ImageView图片重新着色
透明的部分不会改变
1.第一种,设置单一颜色
————>
imageView.setColorFilter(Color.RED);
2.可以设置单一颜色或者selector
Drawable icon = getResources().getDrawable(R.drawable.tabbar_stat);
Drawable tintIcon = DrawableCompat.wrap(icon);
ColorStateList csl=getResources().getColorStateList(R.color.colorAccent);
DrawableCompat.setTintList(tintIcon,csl);
imageView.setImageDrawable(tintIcon);
color的selector:selector_tint.xml(color包)
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:color="@color/colorAccent" android:state_pressed="true"/>
<item android:color="@color/colorPrimary"/>
</selector>
设置selector
Drawable icon = getResources().getDrawable(R.drawable.tabbar_stat);
Drawable tintIcon = DrawableCompat.wrap(icon);
ColorStateList csl=getResources().getColorStateList(R.color.selector_tint);
DrawableCompat.setTintList(tintIcon,csl);
imageView.setImageDrawable(tintIcon);