android.support.v7.widget.DrawableUtils的实例源码

项目:material-toolbar-spinner    文件:AndroidUtils.java   
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;
}
项目:material-toolbar-spinner    文件:AndroidUtils.java   
public static Drawable getTintDrawableByColor(
        Context context,drawableResId);

    if (DrawableUtils.canSafelyMutateDrawable(drawable)) {
        drawable = drawable.mutate();
    }

    Drawable drawableCompat = DrawableCompat.wrap(drawable);
    DrawableCompat.setTint(drawableCompat,color);

    return drawableCompat;
}
项目:CodeColors    文件:TintManagerUtils.java   
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;
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


com.google.gson.internal.bind.ArrayTypeAdapter的实例源码
com.google.gson.JsonSyntaxException的实例源码
com.google.gson.JsonDeserializer的实例源码
com.google.gson.internal.ConstructorConstructor的实例源码
com.google.gson.JsonPrimitive的实例源码
com.google.gson.LongSerializationPolicy的实例源码
com.google.gson.internal.GsonInternalAccess的实例源码
com.google.gson.JsonIOException的实例源码
com.google.gson.internal.StringMap的实例源码
com.google.gson.JsonObject的实例源码
com.google.gson.internal.bind.TimeTypeAdapter的实例源码
com.google.gson.FieldAttributes的实例源码
com.google.gson.internal.bind.TreeTypeAdapter的实例源码
com.google.gson.internal.LinkedHashTreeMap的实例源码
com.google.gson.TypeAdapterFactory的实例源码
com.google.gson.JsonSerializer的实例源码
com.google.gson.FieldNamingPolicy的实例源码
com.google.gson.JsonElement的实例源码
com.google.gson.internal.JsonReaderInternalAccess的实例源码
com.google.gson.TypeAdapter的实例源码