RoundedDrawable

public class RoundedDrawable


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

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

Returns the background color.

@Nullable Drawable

Returns the drawable that will be rendered.

@Override @NonNull int

This method is deprecated.

@NonNull int

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

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

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

@Override @NonNull void
setAlpha(@NonNull int alpha)
@NonNull void

Sets the background color of the rounded drawable.

@NonNull void
setClipEnabled(@NonNull boolean clipEnabled)

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

@Override @NonNull void
@NonNull void

Sets the drawable to be rendered.

@NonNull void
setRadius(@NonNull int radius)

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

Inherited methods

From class Drawable
@NonNull void
@NonNull boolean
@NonNull void
final @NonNull Rect
final @NonNull void
static @NonNull Drawable
static @NonNull Drawable
createFromResourceStream(
    @NonNull Resources res,
    @NonNull TypedValue value,
    @NonNull InputStream is,
    @NonNull String srcName
)
static @NonNull Drawable
static @NonNull Drawable
static @NonNull Drawable
createFromXmlInner(
    @NonNull Resources r,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs
)
final @NonNull Rect
@NonNull Drawable.Callback
@NonNull int
@NonNull ColorFilter
@NonNull Drawable.ConstantState
@NonNull Drawable
@NonNull Rect
@NonNull void
@NonNull int
@NonNull int
@NonNull int
final @NonNull int
@NonNull int
@NonNull int
@NonNull Insets
@NonNull void
@NonNull boolean
@NonNull Array<@NonNull int>
@NonNull Region
@NonNull boolean
@NonNull void
inflate(
    @NonNull Resources r,
    @NonNull XmlPullParser parser,
    @NonNull AttributeSet attrs
)
@NonNull void
@NonNull boolean
@NonNull boolean
@NonNull boolean
@NonNull boolean
final @NonNull boolean
@NonNull void
@NonNull Drawable
@NonNull boolean
onLayoutDirectionChanged(@NonNull int layoutDirection)
static @NonNull int
resolveOpacity(@NonNull int op1, @NonNull int op2)
@NonNull void
scheduleSelf(@NonNull Runnable what, @NonNull long when)
@NonNull void
setAutoMirrored(@NonNull boolean mirrored)
@NonNull void
setBounds(
    @NonNull int left,
    @NonNull int top,
    @NonNull int right,
    @NonNull int bottom
)
final @NonNull void
@NonNull void
@NonNull void
setDither(@NonNull boolean dither)

This method is deprecated.

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

Public constructors

RoundedDrawable

public RoundedDrawable()

Public methods

draw

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

getAlpha

@Override
@NonNull
public @Override int getAlpha()

getBackgroundColor

@ColorInt
@NonNull
public @ColorInt int getBackgroundColor()

Returns the background color.

Returns
@ColorInt int

an ARGB color

getDrawa