Google is committed to advancing racial equity for Black communities. See how.

ShapeableImageView

public class ShapeableImageView
extends AppCompatImageView implements Shapeable

java.lang.Object
   ↳ android.view.View
     ↳ android.widget.ImageView
       ↳ androidx.appcompat.widget.AppCompatImageView
         ↳ com.google.android.material.imageview.ShapeableImageView


An ImageView that draws the bitmap with the provided Shape.

Summary

XML attributes

ShapeableImageView_strokeColor  
ShapeableImageView_strokeWidth  

Inherited constants

From class android.view.View

Inherited fields

From class android.view.View

Public constructors

ShapeableImageView(Context context)
ShapeableImageView(Context context, AttributeSet attrs)
ShapeableImageView(Context context, AttributeSet attrs, int defStyle)

Public methods

ShapeAppearanceModel getShapeAppearanceModel()

Returns the ShapeAppearanceModel used for the shape definition.

ColorStateList getStrokeColor()

Returns the stroke color for this ImageView.

float getStrokeWidth()

Gets the stroke width for this ImageView.

void setShapeAppearanceModel(ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

void setStrokeColor(ColorStateList strokeColor)
void setStrokeColorResource(int strokeColorResourceId)

Sets the stroke color resource for this ImageView.

void setStrokeWidth(float strokeWidth)

Sets the stroke width for this ImageView.

void setStrokeWidthResource(int strokeWidthResourceId)

Sets the stroke width dimension resource for this ImageView.

Protected methods

void onAttachedToWindow()
void onDetachedFromWindow()
void onDraw(Canvas canvas)
void onSizeChanged(int width, int height, int oldWidth, int oldHeight)

Inherited methods

From class androidx.appcompat.widget.AppCompatImageView
From class android.widget.ImageView
From class android.view.View
From class java.lang.Object
From interface androidx.core.view.TintableBackgroundView
From interface androidx.core.widget.TintableImageSourceView
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.accessibility.AccessibilityEventSource
From interface com.google.android.material.shape.Shapeable

XML attributes

ShapeableImageView_strokeColor

Related methods:

ShapeableImageView_strokeWidth

Related methods:

Public constructors

ShapeableImageView

ShapeableImageView (Context context)

Parameters
context Context

ShapeableImageView

ShapeableImageView (Context context, 
                AttributeSet attrs)

Parameters
context Context

attrs AttributeSet

ShapeableImageView

ShapeableImageView (Context context, 
                AttributeSet attrs, 
                int defStyle)

Parameters
context Context

attrs AttributeSet

defStyle int

Public methods

getShapeAppearanceModel

ShapeAppearanceModel getShapeAppearanceModel ()

Returns the ShapeAppearanceModel used for the shape definition.

This ShapeAppearanceModel can be modified to change the shape.

Returns
ShapeAppearanceModel

getStrokeColor

ColorStateList getStrokeColor ()

Returns the stroke color for this ImageView.

Related XML Attributes:

Returns
ColorStateList

getStrokeWidth

float getStrokeWidth ()

Gets the stroke width for this ImageView.

Related XML Attributes:

Returns
float Stroke width for this ImageView.

setShapeAppearanceModel

void setShapeAppearanceModel (ShapeAppearanceModel shapeAppearanceModel)

Sets the ShapeAppearanceModel that defines the shape.

Parameters
shapeAppearanceModel ShapeAppearanceModel

setStrokeColor

void setStrokeColor (ColorStateList strokeColor)

Parameters
strokeColor ColorStateList

setStrokeColorResource

void setStrokeColorResource (int strokeColorResourceId)

Sets the stroke color resource for this ImageView. Both stroke color and stroke width must be set for a stroke to be drawn.

Related XML Attributes:

Parameters
strokeColorResourceId int: Color resource to use for the stroke.

setStrokeWidth

void setStrokeWidth (float strokeWidth)

Sets the stroke width for this ImageView. Both stroke color and stroke width must be set for a stroke to be drawn.

Related XML Attributes:

Parameters
strokeWidth float: Stroke width for this ImageView.

setStrokeWidthResource

void setStrokeWidthResource (int strokeWidthResourceId)

Sets the stroke width dimension resource for this ImageView. Both stroke color and stroke width must be set for a stroke to be drawn.

Related XML Attributes:

Parameters
strokeWidthResourceId int: Stroke width dimension resource for this ImageView.

Protected methods

onAttachedToWindow

void onAttachedToWindow ()

onDetachedFromWindow

void onDetachedFromWindow ()

onDraw

void onDraw (Canvas canvas)

Parameters
canvas Canvas

onSizeChanged

void onSizeChanged (int width, 
                int height, 
                int oldWidth, 
                int oldHeight)

Parameters
width int

height int

oldWidth int

oldHeight int