# RoundedDrawable

Artifact: [androidx.wear:wear](https://developer.android.com/jetpack/androidx/releases/wear) [View Source](https://cs.android.com/search?q=file:androidx/wear/widget/RoundedDrawable.java+class:androidx.wear.widget.RoundedDrawable) Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

*** ** * ** ***


```
public class RoundedDrawable extends Drawable
```

<br />

|---|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object.html) |||
| ↳ | [android.graphics.drawable.Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) ||
|   | ↳ | [androidx.wear.widget.RoundedDrawable](https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable) |

*** ** * ** ***

Maintains and draws a drawable inside rounded rectangular bounds.

The drawable set by the `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setDrawable(android.graphics.drawable.Drawable)` method will be drawn within the rounded bounds specified by `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setBounds(android.graphics.Rect)` and `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setRadius(int)` when the `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#draw(android.graphics.Canvas)` method is called.

By default, RoundedDrawable will apply padding to the drawable inside to fit the drawable into the rounded rectangle. If clipping is enabled by the `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setClipEnabled(boolean)` method, it will clip the drawable to a rounded rectangle instead of resizing it.

The `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setRadius(int)` method is used to specify the amount of border radius applied to the corners of inner drawable, regardless of whether or not the clipping is enabled, border radius will be applied to prevent overflowing of the drawable from specified rounded rectangular area.

RoundedDrawable can be inflated from XML (supported above API level 24) or constructed programmatically. To inflate from XML, use `https://developer.android.com/reference/android/content/Context.html#getDrawable(int)` method.

#### Syntax:

```
<?xml version="1.0" encoding="utf-8"?>
<androidx.wear.widget.RoundedDrawable
  xmlns:android="http://schemas.android.com/apk/res/android"
  xmlns:app="http://schemas.android.com/apk/res-auto"
  android:src="drawable"
  app:backgroundColor="color"
  app:radius="dimension"
app:clipEnabled="boolean" />
```

## Summary

| ### Public constructors |
|---|
| `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#RoundedDrawable()()` |

| ### Public methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#draw(android.graphics.Canvas)(@https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/graphics/Canvas.html canvas)` |
| `int` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#getAlpha()()` |
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#getBackgroundColor()()` Returns the background color. |
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#getDrawable()()` Returns the drawable that will be rendered. |
| `int` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#getOpacity()()` **This method is deprecated.** |
| `int` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#getRadius()()` Returns the border radius applied when rendering the drawable in pixels. |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#inflate(android.content.res.Resources,org.xmlpull.v1.XmlPullParser,android.util.AttributeSet,android.content.res.Resources.Theme)( @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/content/res/Resources.html r, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser, @https://jspecify.dev/docs/api/org/jspecify/annotations/NonNull.html https://developer.android.com/reference/android/util/AttributeSet.html attrs, @https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/content/res/Resources.Theme.html theme )` |
| `boolean` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#isClipEnabled()()` Returns whether the drawable inside is clipped or resized to fit the rounded bounds. |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setAlpha(int)(int alpha)` |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setBackgroundColor(int)(@https://developer.android.com/reference/androidx/annotation/ColorInt int color)` Sets the background color of the rounded drawable. |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setClipEnabled(boolean)(boolean clipEnabled)` Sets whether the drawable inside should be clipped or resized to fit the rounded bounds. |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setColorFilter(android.graphics.ColorFilter)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/ColorFilter.html cf)` |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setDrawable(android.graphics.drawable.Drawable)(@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable)` Sets the drawable to be rendered. |
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#setRadius(int)(int radius)` Sets the border radius to be applied when rendering the drawable in pixels. |

| ### Protected methods |
|---|---|
| `void` | `https://developer.android.com/reference/androidx/wear/widget/RoundedDrawable#onBoundsChange(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html bounds)` |

| ### Inherited methods |
|---|
| From [android.graphics.drawable.Drawable](https://developer.android.com/reference/android/graphics/drawable/Drawable.html) |---|---| | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#applyTheme(android.content.res.Resources.Theme)(https://developer.android.com/reference/android/content/res/Resources.Theme.html t)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#canApplyTheme()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#clearColorFilter()()` | | `final https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#copyBounds()()` | | `final void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#copyBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html bounds)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromPath(java.lang.String)(https://developer.android.com/reference/java/lang/String.html pathName)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromResourceStream(android.content.res.Resources, android.util.TypedValue, java.io.InputStream, java.lang.String)( https://developer.android.com/reference/android/content/res/Resources.html res, https://developer.android.com/reference/android/util/TypedValue.html value, https://developer.android.com/reference/java/io/InputStream.html is, https://developer.android.com/reference/java/lang/String.html srcName )` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromStream(java.io.InputStream, java.lang.String)(https://developer.android.com/reference/java/io/InputStream.html is, https://developer.android.com/reference/java/lang/String.html srcName)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromXml(android.content.res.Resources, org.xmlpull.v1.XmlPullParser)(https://developer.android.com/reference/android/content/res/Resources.html r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser)` | | `static https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#createFromXmlInner(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet)( https://developer.android.com/reference/android/content/res/Resources.html r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser, https://developer.android.com/reference/android/util/AttributeSet.html attrs )` | | `final https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getBounds()()` | | `https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCallback()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getChangingConfigurations()()` | | `https://developer.android.com/reference/android/graphics/ColorFilter.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getColorFilter()()` | | `https://developer.android.com/reference/android/graphics/drawable/Drawable.ConstantState.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getConstantState()()` | | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getCurrent()()` | | `https://developer.android.com/reference/android/graphics/Rect.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getDirtyBounds()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getHotspotBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html outRect)` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicHeight()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getIntrinsicWidth()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getLayoutDirection()()` | | `final int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getLevel()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getMinimumHeight()()` | | `int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getMinimumWidth()()` | | `https://developer.android.com/reference/android/graphics/Insets.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getOpticalInsets()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getOutline(android.graphics.Outline)(https://developer.android.com/reference/android/graphics/Outline.html outline)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getPadding(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html padding)` | | `int[]` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getState()()` | | `https://developer.android.com/reference/android/graphics/Region.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#getTransparentRegion()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#hasFocusStateSpecified()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#inflate(android.content.res.Resources, org.xmlpull.v1.XmlPullParser, android.util.AttributeSet)(https://developer.android.com/reference/android/content/res/Resources.html r, https://developer.android.com/reference/org/xmlpull/v1/XmlPullParser.html parser, https://developer.android.com/reference/android/util/AttributeSet.html attrs)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#invalidateSelf()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isAutoMirrored()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isFilterBitmap()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isProjected()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isStateful()()` | | `final boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#isVisible()()` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#jumpToCurrentState()()` | | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#mutate()()` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onLayoutDirectionChanged(int)(int layoutDirection)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onLevelChange(int)(int level)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#onStateChange(int[])(int[] state)` | | `static int` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#resolveOpacity(int, int)(int op1, int op2)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#scheduleSelf(java.lang.Runnable, long)(https://developer.android.com/reference/java/lang/Runnable.html what, long when)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setAutoMirrored(boolean)(boolean mirrored)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setBounds(android.graphics.Rect)(https://developer.android.com/reference/android/graphics/Rect.html bounds)` | | `final void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setCallback(android.graphics.drawable.Drawable.Callback)(https://developer.android.com/reference/android/graphics/drawable/Drawable.Callback.html cb)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setChangingConfigurations(int)(int configs)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setDither(boolean)(boolean dither)` **This method is deprecated.** | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setFilterBitmap(boolean)(boolean filter)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setHotspot(float, float)(float x, float y)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setHotspotBounds(int, int, int, int)(int left, int top, int right, int bottom)` | | `final boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setLayoutDirection(int)(int layoutDirection)` | | `final boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setLevel(int)(int level)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setState(int[])(int[] stateSet)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTint(int)(int tintColor)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintBlendMode(android.graphics.BlendMode)(https://developer.android.com/reference/android/graphics/BlendMode.html blendMode)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintList(android.content.res.ColorStateList)(https://developer.android.com/reference/android/content/res/ColorStateList.html tint)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setTintMode(android.graphics.PorterDuff.Mode)(https://developer.android.com/reference/android/graphics/PorterDuff.Mode.html tintMode)` | | `boolean` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#setVisible(boolean, boolean)(boolean visible, boolean restart)` | | `void` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html#unscheduleSelf(java.lang.Runnable)(https://developer.android.com/reference/java/lang/Runnable.html what)` | |

## Public constructors

### RoundedDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public RoundedDrawable()
```

## Public methods

### draw

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void draw(@NonNull Canvas canvas)
```

### getAlpha

```
public int getAlpha()
```

### getBackgroundColor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public @ColorInt int getBackgroundColor()
```

Returns the background color.

| Returns |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int` | an ARGB color |

### getDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public @Nullable Drawable getDrawable()
```

Returns the drawable that will be rendered.

| Returns |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` that will be rendered. |

### getOpacity

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public int getOpacity()
```

> [!CAUTION]
> **This method is deprecated.**   

### getRadius

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public int getRadius()
```

Returns the border radius applied when rendering the drawable in pixels.

| Returns |
|---|---|
| `int` | radius in pixels |

### inflate

```
public void inflate(
    @NonNull Resources r,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs,
    @Nullable Resources.Theme theme
)
```

| Throws |
|---|---|
| `https://developer.android.com/reference/org/xmlpull/v1/XmlPullParserException.html` |   |
| `https://developer.android.com/reference/java/io/IOException.html` |   |

### isClipEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public boolean isClipEnabled()
```

Returns whether the drawable inside is clipped or resized to fit the rounded bounds.

| Returns |
|---|---|
| `boolean` | `true` if the drawable is clipped, `false` if it's resized. |

### setAlpha

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void setAlpha(int alpha)
```

### setBackgroundColor

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void setBackgroundColor(@ColorInt int color)
```

Sets the background color of the rounded drawable.

| Parameters |
|---|---|
| `@https://developer.android.com/reference/androidx/annotation/ColorInt int color` | an ARGB color `https://developer.android.com/reference/androidx/wear/R.attr#backgroundColor()` |

### setClipEnabled

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void setClipEnabled(boolean clipEnabled)
```

Sets whether the drawable inside should be clipped or resized to fit the rounded bounds. If the drawable is animated, don't set clipping to `true` as clipping on animated drawables is not supported.

| Parameters |
|---|---|
| `boolean clipEnabled` | `true` if the drawable should be clipped, `false` if it should be resized. clipEnabled |

### setColorFilter

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void setColorFilter(@Nullable ColorFilter cf)
```

### setDrawable

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void setDrawable(@Nullable Drawable drawable)
```

Sets the drawable to be rendered.

| Parameters |
|---|---|
| `@https://jspecify.dev/docs/api/org/jspecify/annotations/Nullable.html https://developer.android.com/reference/android/graphics/drawable/Drawable.html drawable` | `https://developer.android.com/reference/android/graphics/drawable/Drawable.html` to be rendered `https://developer.android.com/reference/android/R.attr.html#src` |

### setRadius

Added in [1.1.0](https://developer.android.com/jetpack/androidx/releases/wear#1.1.0)

```
public void setRadius(int radius)
```

Sets the border radius to be applied when rendering the drawable in pixels.

| Parameters |
|---|---|
| `int radius` | radius in pixels radius |

## Protected methods

### onBoundsChange

```
protected void onBoundsChange(Rect bounds)
```