当前位置: 首页>>代码示例>>Java>>正文


Java DrawableUtils.canSafelyMutateDrawable方法代码示例

本文整理汇总了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;
}
 
开发者ID:Magora-Android,项目名称:material-toolbar-spinner,代码行数:17,代码来源:AndroidUtils.java

示例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;
}
 
开发者ID:Magora-Android,项目名称:material-toolbar-spinner,代码行数:16,代码来源:AndroidUtils.java

示例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;
}
 
开发者ID:Leao,项目名称:CodeColors,代码行数:40,代码来源:TintManagerUtils.java


注:本文中的android.support.v7.widget.DrawableUtils.canSafelyMutateDrawable方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。