Join us on the livestream at Android Dev Summit on 7-8 November 2018, starting at 10AM PDT!

MaterialShapeDrawable

public class MaterialShapeDrawable
extends Drawable implements TintAwareDrawable

java.lang.Object
   ↳ android.graphics.drawable.Drawable
     ↳ com.google.android.material.shape.MaterialShapeDrawable


Base drawable class for Material Shapes that handles shadows, elevation, scale and color for a generated path.

Summary

Public constructors

MaterialShapeDrawable()

Instantiate a basic Material Shape Drawable with no ShapePathModel.

MaterialShapeDrawable(ShapePathModel shapePathModel)

Instantiate with a given model.

Public methods

void draw(Canvas canvas)
float getInterpolation()

Get the interpolation of the path, between 0 and 1.

int getOpacity()
Paint.Style getPaintStyle()

Get the current style used by the shape's paint.

void getPathForSize(int width, int height, Path path)

Writes to the given Path for the current edge and corner treatments at the specified size.

float getScale()

Get the scale of the rendered path.

int getShadowElevation()

Get the shadow elevation rendered by the path.

int getShadowRadius()

Get the shadow radius rendered by the path.

ShapePathModel getShapedViewModel()

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

float getStrokeWidth()

Get the stroke width used by the shape's paint.

ColorStateList getTintList()

Get the tint list used by the shape's paint.

Region getTransparentRegion()
boolean isPointInTransparentRegion(int x, int y)

Determines whether a point is contained within the transparent region of the Drawable.

boolean isShadowEnabled()

Get shadow rendering status.

void setAlpha(int alpha)
void setColorFilter(ColorFilter colorFilter)
void setInterpolation(float interpolation)

Set the interpolation of the path, between 0 and 1.

void setPaintStyle(Paint.Style paintStyle)

Set the style used by the shape's paint.

void setScale(float scale)

Set the scale of the rendered path.

void setShadowColor(int shadowColor)

Set color of shadow rendered behind shape.

void setShadowElevation(int shadowElevation)

Set the shadow elevation rendered by the path.

void setShadowEnabled(boolean shadowEnabled)

Set shadow rendering enabled or disabled.

void setShadowRadius(int shadowRadius)

Set the shadow radius rendered by the path.

void setShapedViewModel(ShapePathModel shapedViewModel)

Set the ShapePathModel containing the path that will be rendered in this drawable.

void setStrokeWidth(float strokeWidth)

Set the stroke width used by the shape's paint.

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

Set whether shadow color should match next set tint color.

Inherited methods

From class android.graphics.drawable.Drawable
From class java.lang.Object
From interface android.support.v4.graphics.drawable.TintAwareDrawable

Public constructors

MaterialShapeDrawable

MaterialShapeDrawable ()

Instantiate a basic Material Shape Drawable with no ShapePathModel.

MaterialShapeDrawable

MaterialShapeDrawable (ShapePathModel shapePathModel)

Instantiate with a given model.

Parameters
shapePathModel ShapePathModel: the ShapePathModel containing the path that will be rendered in this drawable.

Public methods

draw

void draw (Canvas canvas)

Parameters
canvas Canvas

getInterpolation

float getInterpolation ()

Get the interpolation of the path, between 0 and 1. Ranges between 0 (none) and 1 (fully) interpolated.

Returns
float the interpolation of the path.

getOpacity

int getOpacity ()

Returns
int

getPaintStyle

Paint.Style getPaintStyle ()

Get the current style used by the shape's paint.

Returns
Paint.Style current used paint style.

getPathForSize

void getPathForSize (int width, 
                int height, 
                Path path)

Writes to the given Path for the current edge and corner treatments at the specified size.

Parameters
width int: width of target path.

height int: height of target path.

path Path: the returned path out-var.

Returns
void the generated path.

getScale

float getScale ()

Get the scale of the rendered path. A value of 1 renders it at 100% size.

Returns
float the scale of the path.

getShadowElevation

int getShadowElevation ()

Get the shadow elevation rendered by the path.

Returns
int shadow elevation rendered by the path.

getShadowRadius

int getShadowRadius ()

Get the shadow radius rendered by the path.

Returns
int the shadow radius rendered by the path.

getShapedViewModel

ShapePathModel getShapedViewModel ()

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

Returns
ShapePathModel the current model.

getStrokeWidth

float getStrokeWidth ()

Get the stroke width used by the shape's paint.

Returns
float current stroke width.

getTintList

ColorStateList getTintList ()

Get the tint list used by the shape's paint.

Returns
ColorStateList current tint list.

getTransparentRegion

Region getTransparentRegion ()

Returns
Region

isPointInTransparentRegion

boolean isPointInTransparentRegion (int x, 
                int y)

Determines whether a point is contained within the transparent region of the Drawable. A return value of true generally suggests that the touched view should not process a touch event at that point.

Parameters
x int: The X coordinate of the point.

y int: The Y coordinate of the point.

Returns
boolean true iff the point is contained in the transparent region of the Drawable.

isShadowEnabled

boolean isShadowEnabled ()

Get shadow rendering status.

Returns
boolean true if shadows are enabled; false if not.

setAlpha

void setAlpha (int alpha)

Parameters
alpha int

setColorFilter

void setColorFilter (ColorFilter colorFilter)

Parameters
colorFilter ColorFilter

setInterpolation

void setInterpolation (float interpolation)

Set the interpolation of the path, between 0 and 1. Ranges between 0 (none) and 1 (fully) interpolated. An interpolation of 1 generally indicates a fully rendered path, while an interpolation of 0 generally indicates a fully healed path, which is usually a rectangle.

Parameters
interpolation float: the desired interpolation.

setPaintStyle

void setPaintStyle (Paint.Style paintStyle)

Set the style used by the shape's paint.

Parameters
paintStyle Paint.Style: the desired style.

setScale

void setScale (float scale)

Set the scale of the rendered path. A value of 1 renders it at 100% size.

Parameters
scale float: the desired scale.

setShadowColor

void setShadowColor (int shadowColor)

Set color of shadow rendered behind shape.

Parameters
shadowColor int: desired color.

setShadowElevation

void setShadowElevation (int shadowElevation)

Set the shadow elevation rendered by the path.

Parameters
shadowElevation int: the desired elevation.

setShadowEnabled

void setShadowEnabled (boolean shadowEnabled)

Set shadow rendering enabled or disabled.

Parameters
shadowEnabled boolean: true if shadows are enabled; false if not.

setShadowRadius

void setShadowRadius (int shadowRadius)

Set the shadow radius rendered by the path.

Parameters
shadowRadius int: the desired shadow radius.

setShapedViewModel

void setShapedViewModel (ShapePathModel shapedViewModel)

Set the ShapePathModel containing the path that will be rendered in this drawable.

Parameters
shapedViewModel ShapePathModel: the desired model.

setStrokeWidth

void setStrokeWidth (float strokeWidth)

Set the stroke width used by the shape's paint.

Parameters
strokeWidth float: desired stroke width.

setTint

void setTint (int tintColor)

Parameters
tintColor int

setTintList

void setTintList (ColorStateList tintList)

Parameters
tintList ColorStateList

setTintMode

void setTintMode (PorterDuff.Mode tintMode)

Parameters
tintMode PorterDuff.Mode

setUseTintColorForShadow

void setUseTintColorForShadow (boolean useTintColorForShadow)

Set whether shadow color should match next set tint color.

Parameters
useTintColorForShadow boolean: true if color should match; false otherwise.