RoundedDrawable
class RoundedDrawable : 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 functions |
|
|---|---|
Unit |
|
Int |
getAlpha() |
@ColorInt Int |
Returns the background color. |
Drawable? |
Returns the drawable that will be rendered. |
Int |
This function is deprecated. |
Int |
Returns the border radius applied when rendering the drawable in pixels. |
Unit |
inflate( |
Boolean |
Returns whether the drawable inside is clipped or resized to fit the rounded bounds. |
Unit |
|
Unit |
setBackgroundColor(color: @ColorInt Int)Sets the background color of the rounded drawable. |
Unit |
setClipEnabled(clipEnabled: Boolean)Sets whether the drawable inside should be clipped or resized to fit the rounded bounds. |
Unit |
setColorFilter(cf: ColorFilter?) |
Unit |
setDrawable(drawable: Drawable?)Sets the drawable to be rendered. |
Unit |
Sets the border radius to be applied when rendering the drawable in pixels. |
Protected functions |
|
|---|---|
Unit |
onBoundsChange(bounds: Rect!) |
Public constructors
Public functions
getBackgroundColor
fun getBackgroundColor(): @ColorInt Int
Returns the background color.
getRadius
fun getRadius(): Int
Returns the border radius applied when rendering the drawable in pixels.
| Returns | |
|---|---|
Int |
radius in pixels |
inflate
fun inflate(
r: Resources,
parser: XmlPullParser,
attrs: AttributeSet,
theme: Resources.Theme?
): Unit
isClipEnabled
fun isClipEnabled(): Boolean
Returns whether the drawable inside is clipped or resized to fit the rounded bounds.
| Returns | |
|---|---|
Boolean |
|
setBackgroundColor
fun setBackgroundColor(color: @ColorInt Int): Unit
Sets the background color of the rounded drawable.
| Parameters | |
|---|---|
color: @ColorInt Int |
an ARGB color |
setClipEnabled
fun setClipEnabled(clipEnabled: Boolean): Unit
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 | |
|---|---|
clipEnabled: Boolean |
|
setDrawable
fun setDrawable(drawable: Drawable?): Unit
Sets the drawable to be rendered.