set Drawable Color - Android Graphics

Android examples for Graphics:Drawable

Description

set Drawable Color

Demo Code


//package com.java2s;
import android.graphics.ColorFilter;
import android.graphics.PorterDuff;
import android.graphics.PorterDuffColorFilter;
import android.graphics.drawable.Drawable;
import android.support.annotation.NonNull;

public class Main {
    public static Drawable setColor(@NonNull Drawable drawable, int color) {
        final Drawable out = drawable.mutate();
        out.setColorFilter(getColorFilter(color));
        return out;
    }//  ww w.j a va 2 s . com

    public static ColorFilter getColorFilter(int color) {
        return new PorterDuffColorFilter(color, PorterDuff.Mode.MULTIPLY);
    }
}

Related Tutorials