/**
* Tries to clone and just color filter the drawable. Uses mode SRC_ATOP.
*
* @param drawable Which drawable to color
* @param color Which color to use
* @return A colored drawable ready for use
*/
@SuppressWarnings("RedundantCast")
public Drawable colorUnknownDrawable(@Nullable Drawable drawable, int color) {
if (drawable instanceof DrawableWrapper || drawable instanceof android.support.v7.graphics.drawable.DrawableWrapper) {
drawable = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawable, color);
DrawableCompat.setTintMode(drawable, PorterDuff.Mode.SRC_ATOP);
drawable = DrawableCompat.unwrap(drawable);
return drawable;
} else {
try {
// noinspection ConstantConditions
Drawable copy = drawable.getConstantState().newDrawable();
copy.mutate();
copy.setColorFilter(color, SRC_ATOP);
return copy;
} catch (Exception e) {
if (drawable != null) {
Log.d(LOG_TAG, "Failed to color unknown drawable: " + drawable.getClass().getSimpleName());
}
return drawable;
}
}
}
Coloring.java 文件源码
java
阅读 43
收藏 0
点赞 0
评论 0
项目:actual-number-picker
作者:
评论列表
文章目录