set TextView Compound Drawable Filter - Android User Interface

Android examples for User Interface:TextView

Description

set TextView Compound Drawable Filter

Demo Code


import android.graphics.PorterDuff;
import android.graphics.drawable.Drawable;
import android.support.annotation.IntDef;
import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

public class Main{
    /*from ww  w . j a  v  a2 s . c  o m*/
    public static void setCompoundDrawableFilter(TextView textView,
            @Duration int duration, int color) {
        Drawable[] drawables = textView.getCompoundDrawables();
        if (null != textView) {
            setDrawableFilter(drawables[duration], color);
        }
    }
    
    public static void setDrawableFilter(Drawable drawable, int color) {
        if (null != drawable) {
            drawable.setColorFilter(color, PorterDuff.Mode.MULTIPLY);
        }
    }
}

Related Tutorials