Example usage for android.graphics.drawable RippleDrawable getDrawable

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

Introduction

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

Prototype

public Drawable getDrawable(int index) 

Source Link

Document

Returns the drawable for the layer at the specified index.

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  w ww  .  ja  v a2 s . com*/
        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  a  va 2s.  co  m*/
}