Skip to content

Instantly share code, notes, and snippets.

@Eklett
Last active December 17, 2016 07:55
Show Gist options
  • Save Eklett/4c60fe233da6e2f3c855c2c2c0978457 to your computer and use it in GitHub Desktop.
Save Eklett/4c60fe233da6e2f3c855c2c2c0978457 to your computer and use it in GitHub Desktop.
与drawable相关的一些操作
import android.graphics.drawable.Drawable;
import android.graphics.PorterDuff;
import android.support.annotation.ColorInt;
import android.support.v4.graphics.drawable.DrawableCompat;
import android.widget.ImageView;
public class DrawableUtils {
/**
* 以SRC_ATOP的方式改变imageview图片的颜色
*/
public static void changeImageDrawable(ImageView imageView, @ColorInt int color) {
Drawable drawable = imageView.getDrawable();
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, color);
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP);
imageView.setImageDrawable(drawable);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment