Save the date! Android Dev Summit is coming to Mountain View, CA on November 7-8, 2018.

androidx.core.graphics.drawable

Classes

DrawableCompat

Helper for accessing features in android.graphics.drawable.Drawable.

IconCompat

Helper for accessing features in android.graphics.drawable.Icon.

RoundedBitmapDrawable

A Drawable that wraps a bitmap and can be drawn with rounded corners.

RoundedBitmapDrawableFactory

Constructs RoundedBitmapDrawable objects, either from Bitmaps directly, or from streams and files.

Extension functions summary

For android.graphics.Bitmap
BitmapDrawable

Create a BitmapDrawable from this Bitmap.

Icon

Create an Icon from this adaptive Bitmap.

Icon

Create an Icon from this Bitmap.

For kotlin.Int
ColorDrawable

Create a ColorDrawable from this color value.

For android.graphics.Color
ColorDrawable

Create a ColorDrawable from this Color (via Color.toArgb).

For android.graphics.drawable.Drawable
Bitmap
Drawable.toBitmap(width: Int = intrinsicWidth, height: Int = intrinsicHeight, config: Config? = null)

Return a Bitmap representation of this Drawable.

Unit
Drawable.updateBounds(left: Int = bounds.left, top: Int = bounds.top, right: Int = bounds.right, bottom: Int = bounds.bottom)

Updates this drawable's bounds.

For android.net.Uri
Icon

Create an Icon from this Uri.

For kotlin.ByteArray
Icon

Create an Icon from this ByteArray.

Extension functions

toAdaptiveIcon

inline fun Bitmap.toAdaptiveIcon(): Icon

Create an Icon from this adaptive Bitmap.

toBitmap

fun Drawable.toBitmap(width: Int = intrinsicWidth, height: Int = intrinsicHeight, config: Config? = null): Bitmap

Return a Bitmap representation of this Drawable.

If this instance is a BitmapDrawable and the width, height, and config match, the underlying Bitmap instance will be returned directly. If any of those three properties differ then a new Bitmap is created. For all other Drawable types, a new Bitmap is created.

Parameters
width Width of the desired bitmap. Defaults to Drawable.getIntrinsicWidth.
height Height of the desired bitmap. Defaults to Drawable.getIntrinsicHeight.
config Bitmap config of the desired bitmap. Null attempts to use the native config, if any. Defaults to Config.ARGB_8888 otherwise.

toDrawable

inline fun Bitmap.toDrawable(resources: Resources): BitmapDrawable

Create a BitmapDrawable from this Bitmap.

toDrawable

inline fun Int.toDrawable(): ColorDrawable

Create a ColorDrawable from this color value.

toDrawable

inline fun Color.toDrawable(): ColorDrawable

Create a ColorDrawable from this Color (via Color.toArgb).

toIcon

inline fun Bitmap.toIcon(): Icon

Create an Icon from this Bitmap.

toIcon

inline fun Uri.toIcon(): Icon

Create an Icon from this Uri.

toIcon

inline fun ByteArray.toIcon(): Icon

Create an Icon from this ByteArray.

updateBounds

fun Drawable.updateBounds(left: Int = bounds.left, top: Int = bounds.top, right: Int = bounds.right, bottom: Int = bounds.bottom): Unit

Updates this drawable's bounds. This version of the method allows using named parameters to just set one or more axes.