本文整理汇总了Java中android.support.v7.widget.DrawableUtils.canSafelyMutateDrawable方法的典型用法代码示例。如果您正苦于以下问题:Java DrawableUtils.canSafelyMutateDrawable方法的具体用法?Java DrawableUtils.canSafelyMutateDrawable怎么用?Java DrawableUtils.canSafelyMutateDrawable使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类android.support.v7.widget.DrawableUtils
的用法示例。
在下文中一共展示了DrawableUtils.canSafelyMutateDrawable方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTintDrawableByColor2
import android.support.v7.widget.DrawableUtils; //导入方法依赖的package包/类
public static Drawable getTintDrawableByColor2(
Context context,
@DrawableRes int drawableResId,
@ColorInt int color) {
Drawable drawable = AndroidUtils.getDrawable(context, drawableResId);
if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
drawable = drawable.mutate();
}
PorterDuffColorFilter filter
= new PorterDuffColorFilter(color, PorterDuff.Mode.SRC_IN);
drawable.setColorFilter(filter);
return drawable;
}
示例2: getTintDrawableByColor
import android.support.v7.widget.DrawableUtils; //导入方法依赖的package包/类
public static Drawable getTintDrawableByColor(
Context context,
@DrawableRes int drawableResId,
@ColorInt int color) {
Drawable drawable = AndroidUtils.getDrawable(context, drawableResId);
if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
drawable = drawable.mutate();
}
Drawable drawableCompat = DrawableCompat.wrap(drawable);
DrawableCompat.setTint(drawableCompat, color);
return drawableCompat;
}
示例3: tintDrawableUsingColorFilter
import android.support.v7.widget.DrawableUtils; //导入方法依赖的package包/类
public static boolean tintDrawableUsingColorFilter(@NonNull Context context, @DrawableRes final int resId,
@NonNull Drawable drawable) {
PorterDuff.Mode tintMode = DEFAULT_MODE;
boolean colorAttrSet = false;
int colorAttr = 0;
int alpha = -1;
if (arrayContains(COLORFILTER_TINT_COLOR_CONTROL_NORMAL, resId)) {
colorAttr = R.attr.colorControlNormal;
colorAttrSet = true;
} else if (arrayContains(COLORFILTER_COLOR_CONTROL_ACTIVATED, resId)) {
colorAttr = R.attr.colorControlActivated;
colorAttrSet = true;
} else if (arrayContains(COLORFILTER_COLOR_BACKGROUND_MULTIPLY, resId)) {
colorAttr = android.R.attr.colorBackground;
colorAttrSet = true;
tintMode = PorterDuff.Mode.MULTIPLY;
} else if (resId == R.drawable.abc_list_divider_mtrl_alpha) {
colorAttr = android.R.attr.colorForeground;
colorAttrSet = true;
alpha = Math.round(0.16f * 255);
}
if (colorAttrSet) {
if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
drawable = drawable.mutate();
}
final int color = getThemeAttrColor(context, colorAttr);
drawable.setColorFilter(getPorterDuffColorFilter(color, tintMode));
if (alpha != -1) {
drawable.setAlpha(alpha);
}
return true;
}
return false;
}