Android 12 Developer Preview is here! Try it out, and give us your feedback!

RippleDrawableCompat

public class RippleDrawableCompat
extends Drawable implements Shapeable, TintAwareDrawable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ com.google.android.material.ripple.RippleDrawableCompat


A compat Drawable that is used to provide an overlay for pressed, focused, and hovered states (only when in enabled). This is intended to be used pre-Lollipop.

This Drawable is a MaterialShapeDrawable so that it can be shaped to match a MaterialShapeDrawable background.

Unlike the framework RippleDrawable, this will not apply different alphas for pressed, focused, and hovered states and it does not provide a ripple animation for the pressed state.

Summary

Public constructors

RippleDrawableCompat(ShapeAppearanceModel shapeAppearanceModel)

Creates a RippleDrawableCompat with the given shape that will only draw when enabled and at leaste one of: presssed, focused, or hovered.

Public methods

void draw(Canvas canvas)
Drawable.ConstantState getConstantState()
int getOpacity()
ShapeAppearanceModel getShapeAppearanceModel()

Get the ShapeAppearanceModel containing the path that will be rendered in this drawable.

boolean isStateful()
RippleDrawableCompat mutate()
void setAlpha(int alpha)
void setColorFilter(ColorFilter colorFilter)
void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

void setTint(int tintColor)
void setTintList(ColorStateList tintList)
void setTintMode(PorterDuff.Mode tintMode)

Protected methods

void onBoundsChange(Rect bounds)
boolean onStateChange(int[] stateSet)

Inherited methods

Public constructors

RippleDrawableCompat

public RippleDrawableCompat (ShapeAppearanceModel shapeAppearanceModel)

Creates a RippleDrawableCompat with the given shape that will only draw when enabled and at leaste one of: presssed, focused, or hovered.

Parameters
shapeAppearanceModel ShapeAppearanceModel: The shape for the ripple.

Public methods

draw

public void draw (Canvas canvas)

Parameters
canvas Canvas

getConstantState

public Drawable.ConstantState getConstantState ()

Returns
Drawable.ConstantState

getOpacity

public int getOpacity ()

Returns
int

getShapeAppearanceModel

public ShapeAppearanceModel getShapeAppearanceModel ()

Get the ShapeAppearanceModel containing the path that will be rendered in this drawable.

Returns
ShapeAppearanceModel the current model.

isStateful

public boolean isStateful ()

Returns
boolean

mutate

public RippleDrawableCompat mutate ()

Returns
RippleDrawableCompat

setAlpha

public void setAlpha (int alpha)

Parameters
alpha int

setColorFilter

public void setColorFilter (ColorFilter colorFilter)

Parameters
colorFilter ColorFilter

setShapeAppearanceModel

public void setShapeAppearanceModel (ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

Parameters
shapeAppearanceModel ShapeAppearanceModel

setTint

public void setTint (int tintColor)

Parameters
tintColor int

setTintList

public void setTintList (ColorStateList tintList)

Parameters
tintList ColorStateList

setTintMode

public void setTintMode (PorterDuff.Mode tintMode)

Parameters
tintMode PorterDuff.Mode

Protected methods

onBoundsChange

protected void onBoundsChange (Rect bounds)

Parameters
bounds Rect

onStateChange

protected boolean onStateChange (int[] stateSet)

Parameters
stateSet int

Returns
boolean