爲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);