/**
* Sets a tint on top of the desired drawable
*
* @param drawable source drawable to apply the tint
* @param tintColorInt color int of the desired tint
*/
public static void setDrawableTint(@NonNull final Drawable drawable,
@ColorInt final int tintColorInt) {
/*
* === FIXED ===
* In the latest support library, DrawableCompat.wrap() is no longer needed
*
* There is an invalidation issue when setting drawable state on pre-lollipop devices,
* even if using the DrawableCompat.setTint() method. It appears to be google support
* library issue. The get around is to use DrawableCompat.wrap() to wrap the drawable
* before setting tint color
*
* http://stackoverflow.com/questions/30872101
* https://code.google.com/p/android/issues/detail?id=172067#c13
* =============
*/
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) {
/*
* Tint ONLY the targeted drawable without affecting other drawables in the app.
*
* http://stackoverflow.com/questions/26788251
*/
Drawable mutateDrawable = drawable.mutate();
// Work for API 17 and below as well
mutateDrawable.setColorFilter(tintColorInt, PorterDuff.Mode.SRC_IN);
} else {
DrawableCompat.setTint(drawable, tintColorInt);
}
}
AbstractDrawableUtils.java 文件源码
java
阅读 30
收藏 0
点赞 0
评论 0
项目:tenor-android-demo-search
作者:
评论列表
文章目录