Example usage for android.graphics.drawable StateListDrawable setColorFilter

List of usage examples for android.graphics.drawable StateListDrawable setColorFilter

Introduction

In this page you can find the example usage for android.graphics.drawable StateListDrawable setColorFilter.

Prototype

public void setColorFilter(@ColorInt int color, @NonNull PorterDuff.Mode mode) 

Source Link

Document

Specify a color and Porter-Duff mode to be the color filter for this drawable.

Usage

From source file:com.varejodigital.activities.DetailActivity.java

private void updateBackground(View view, Palette palette) {
    int lightMutedColor = palette.getLightMutedColor(getResources().getColor(R.color.accent));
    int mutedColor = palette.getMutedColor(getResources().getColor(R.color.accent));

    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        RippleDrawable ripple = (RippleDrawable) view.getBackground();
        GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0);
        rippleBackground.setColor(lightMutedColor);
        ripple.setColor(ColorStateList.valueOf(mutedColor));
    } else {//from  ww  w  . j  ava  2  s.com
        StateListDrawable drawable = (StateListDrawable) view.getBackground();
        drawable.setColorFilter(mutedColor, PorterDuff.Mode.SRC_ATOP);
    }
}