public final class DrawableUtils {
public static Drawable applyColorFilter(@NonNull Context context, @DrawableRes int drawableId, @ColorRes int colorId, @NonNull PorterDuff.Mode mode) {
Drawable d = ContextCompat.getDrawable(context, drawableId);
int color = ContextCompat.getColor(context, colorId);
d.setColorFilter(color, mode);
return d;
}
public static Drawable applyColorFilter(@NonNull Context context, @DrawableRes int drawableId) {
return applyColorFilter(context, drawableId, R.color.colorPrimaryDark, PorterDuff.Mode.SRC_ATOP);
}
}
public static Drawable applyColorFilter(@NonNull Context context, @DrawableRes int drawableId, @ColorRes int colorId, @NonNull PorterDuff.Mode mode) {
Drawable d = ContextCompat.getDrawable(context, drawableId);
int color = ContextCompat.getColor(context, colorId);
d.setColorFilter(color, mode);
return d;
}
public static Drawable applyColorFilter(@NonNull Context context, @DrawableRes int drawableId) {
return applyColorFilter(context, drawableId, R.color.colorPrimaryDark, PorterDuff.Mode.SRC_ATOP);
}
}