/**
* Colors the given drawable to the specified color. Uses {@link PorterDuff.Mode#SRC_ATOP}.
*
* @param context Which context to use
* @param drawable Which drawable to color
* @param color Which color to use
* @return A colored drawable, new instance in most cases for bitmaps, cached instance for most other cases
*/
@NonNull
public static Drawable colorDrawable(@NonNull final Context context, @NonNull final Drawable drawable, @ColorInt final int color) {
if (drawable instanceof VectorDrawable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
return colorVectorDrawable((VectorDrawable) drawable, color);
}
if (drawable instanceof VectorDrawableCompat) {
return colorVectorDrawableCompat((VectorDrawableCompat) drawable, color);
}
if (drawable instanceof ColorDrawable && Build.VERSION.SDK_INT >= Build.VERSION_CODES.HONEYCOMB) {
((ColorDrawable) drawable).setColor(color);
return drawable;
}
if (drawable instanceof GradientDrawable) {
drawable.setColorFilter(color, PorterDuff.Mode.SRC_ATOP);
return drawable;
}
if (drawable instanceof BitmapDrawable) {
final Bitmap bitmap = ((BitmapDrawable) drawable).getBitmap();
return new BitmapDrawable(context.getResources(), colorBitmap(bitmap, color));
}
// have no idea what this is..
return colorUnknownDrawable(drawable, color);
}
Coloring.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:silly-android
作者:
评论列表
文章目录