Example usage for android.graphics.drawable RippleDrawable setColor

List of usage examples for android.graphics.drawable RippleDrawable setColor

Introduction

In this page you can find the example usage for android.graphics.drawable RippleDrawable setColor.

Prototype

public void setColor(ColorStateList color) 

Source Link

Document

Sets the ripple color.

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 {//ww  w.  j a  v  a2  s . c o  m
        StateListDrawable drawable = (StateListDrawable) view.getBackground();
        drawable.setColorFilter(mutedColor, PorterDuff.Mode.SRC_ATOP);
    }
}

From source file:fr.outadev.skinswitch.DetailActivity.java

@TargetApi(Build.VERSION_CODES.LOLLIPOP)
private void colorRipple(int id, int tintColor) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        FloatingActionButton buttonView = (FloatingActionButton) findViewById(id);

        RippleDrawable ripple = (RippleDrawable) buttonView.getBackground();
        GradientDrawable rippleBackground = (GradientDrawable) ripple.getDrawable(0);
        rippleBackground.setColor(getResources().getColor(R.color.colorPrimary));

        ripple.setColor(ColorStateList.valueOf(tintColor));
    }//from www .  j ava  2s  .  c om
}