RoundedDrawable

Added in 1.1.0

public class RoundedDrawable extends Drawable


Maintains and draws a drawable inside rounded rectangular bounds.

The drawable set by the setDrawable method will be drawn within the rounded bounds specified by setBounds and setRadius when the draw 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 setClipEnabled method, it will clip the drawable to a rounded rectangle instead of resizing it.

The setRadius 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 getDrawable 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

Public methods

void
draw(@NonNull Canvas canvas)
int
@ColorInt int

Returns the background color.

@Nullable Drawable

Returns the drawable that will be rendered.

int

This method is deprecated.

int

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

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

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

void
setAlpha(int alpha)
void

Sets the background color of the rounded drawable.

void
setClipEnabled(boolean clipEnabled)

Sets whether the drawable inside should be clipped or resized to fit the rounded bounds.

void
void

Sets the drawable to be rendered.

void
setRadius(int radius)

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

Protected methods

void

Inherited methods

From android.graphics.drawable.Drawable
void
boolean
void
final Rect
final void
copyBounds(Rect bounds)
static Drawable
static Drawable
createFromResourceStream(
    Resources res,
    TypedValue value,
    InputStream is,
    String srcName
)
static Drawable
static Drawable
static Drawable
createFromXmlInner(
    Resources r,
    XmlPullParser parser,
    AttributeSet attrs
)
final Rect
Drawable.Callback
int
ColorFilter
Drawable.ConstantState
Drawable
Rect
void
int
int
int
final int
int
int
Insets
void
boolean
getPadding(Rect padding)
int[]
Region
boolean
void
void
boolean
boolean
boolean
boolean
final boolean
void
Drawable
boolean
onLayoutDirectionChanged(int layoutDirection)
boolean
onLevelChange(int level)
boolean
onStateChange(int[] state)
static int
resolveOpacity(int op1, int op2)
void
scheduleSelf(Runnable what, long when)
void
setAutoMirrored(boolean mirrored)
void
setBounds(int left, int top, int right, int bottom)
final void
void
void
setDither(boolean dither)

This method is deprecated.

void
setFilterBitmap(boolean filter)
void
setHotspot(float x, float y)
void
setHotspotBounds(int left, int top, int right, int bottom)
final boolean
setLayoutDirection(int layoutDirection)
final boolean
setLevel(int level)
boolean
setState(int[] stateSet)
void
setTint(int tintColor)
void
void
void
boolean
setVisible(boolean visible, boolean restart)
void

Public constructors

RoundedDrawable

Added in 1.1.0
public RoundedDrawable()

Public methods

draw

Added in 1.1.0
public void draw(@NonNull Canvas canvas)

getAlpha

public int getAlpha()

getBackgroundColor

Added in 1.1.0
public @ColorInt int getBackgroundColor()

Returns the background color.

Returns
@ColorInt int

an ARGB color

getDrawable

Added in 1.1.0
public @Nullable Drawable getDrawable()

Returns the drawable that will be rendered.

Returns
@Nullable Drawable

Drawable that will be rendered.

getOpacity

Added in 1.1.0
public int getOpacity()

getRadius

Added in 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
)

isClipEnabled

Added in 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
public void setAlpha(int alpha)

setBackgroundColor

Added in 1.1.0
public void setBackgroundColor(@ColorInt int color)

Sets the background color of the rounded drawable.

Parameters
@ColorInt int color

an ARGB color backgroundColor

setClipEnabled

Added in 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
public void setColorFilter(@Nullable ColorFilter cf)

setDrawable

Added in 1.1.0
public void setDrawable(@Nullable Drawable drawable)

Sets the drawable to be rendered.

Parameters
@Nullable Drawable drawable

Drawable to be rendered src

setRadius

Added in 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)