O Google tem o compromisso de promover a igualdade racial para as comunidades negras. Saiba como.

androidx.compose.ui.res

Classes

DeferredResource

A class used for the result of the asynchronous resource loading.

FailedResource

A class represents the alternative resource due to failed to load the requested resource.

LoadedResource

A class represents the loaded resource.

PendingResource

A class represents the alternative resource due to background loading.

Resource

The base resource class for background resource loading.

Top-level functions summary

Boolean
booleanResource(@BoolRes id: Int)

Load a boolean resource.

Color
colorResource(@ColorRes id: Int)

Load a color resource.

Dp
dimensionResource(@DimenRes id: Int)

Load a boolean resource.

Typeface
fontResource(fontFamily: FontFamily)

Synchronously load an font from FontFamily.

ImageBitmap
imageResource(@DrawableRes id: Int)

Synchronously load an image resource.

IntArray
integerArrayResource(@ArrayRes id: Int)

Load an array of integer resource.

Int
integerResource(@IntegerRes id: Int)

Load an integer resource.

DeferredResource<Typeface>
loadFontResource(fontFamily: FontFamily, pendingFontFamily: FontFamily? = null, failedFontFamily: FontFamily? = null)

Load the FontFamily in background thread.

DeferredResource<Typeface>
loadFontResource(fontFamily: FontFamily, pendingTypeface: Typeface? = null, failedTypeface: Typeface? = null)

Load the FontFamily in background thread.

DeferredResource<ImageBitmap>
loadImageResource(id: Int, pendingImage: ImageBitmap? = null, failedImage: ImageBitmap? = null)

Load the image in background thread.

DeferredResource<ImageVector>
loadVectorResource(id: Int, pendingResource: ImageVector? = null, failedResource: ImageVector? = null)

Load the vector drawable in background thread.

Painter
painterResource(@DrawableRes id: Int)

Create a Painter from an Android resource id.

Array<String>
stringArrayResource(@ArrayRes id: Int)

Load a string resource.

String
stringResource(@StringRes id: Int)

Load a string resource.

String
stringResource(@StringRes id: Int, vararg formatArgs: Any)

Load a string resource with formatting.

ImageVector
vectorResource(@DrawableRes id: Int)

Load a ImageVector from an Android resource id This is useful for querying top level properties of the ImageVector such as it's intrinsic width and height to be able to size components based off of it's dimensions appropriately

Top-level functions

booleanResource

@Composable fun booleanResource(@BoolRes id: Int): Boolean

Load a boolean resource.

Parameters
id: Int the resource identifier
Return
the boolean associated with the resource

colorResource

@Composable fun colorResource(@ColorRes id: Int): Color

Load a color resource.

Parameters
id: Int the resource identifier
Return
the color associated with the resource

dimensionResource

@Composable fun dimensionResource(@DimenRes id: Int): Dp

Load a boolean resource.

Parameters
id: Int the resource identifier
Return
the dimension value associated with the resource

fontResource

@Composable fun fontResource(fontFamily: FontFamily): Typeface

Synchronously load an font from FontFamily.

Parameters
fontFamily: FontFamily the fontFamily
Return
the decoded image data associated with the resource

imageResource

@Composable fun imageResource(@DrawableRes id: Int): ImageBitmap

Synchronously load an image resource.

Note: This API is transient and will be likely removed for encouraging async resource loading.

For loading generic loading of rasterized or vector assets see painterResource

Parameters
id: Int the resource identifier
Return
the decoded image data associated with the resource

integerArrayResource

@Composable fun integerArrayResource(@ArrayRes id: Int): IntArray

Load an array of integer resource.

Parameters
id: Int the resource identifier
Return
the integer array associated with the resource

integerResource

@Composable fun integerResource(@IntegerRes id: Int): Int

Load an integer resource.

Parameters
id: Int the resource identifier
Return
the integer associated with the resource

loadFontResource

@Composable fun loadFontResource(
    fontFamily: FontFamily,
    pendingFontFamily: FontFamily? = null,
    failedFontFamily: FontFamily? = null
): DeferredResource<Typeface>

Load the FontFamily in background thread.

Until font family loading complete, this function returns deferred Typeface with PendingResource. Once loading finishes, recompose is scheduled and this function will return deferred Typeface resource with LoadedResource or FailedResource.

import androidx.compose.material.Text
import androidx.compose.ui.res.loadFontResource
import androidx.compose.ui.text.font.LoadedFontFamily

loadFontResource(
    FontFamily.Default,
    pendingFontFamily = FontFamily.Cursive,
    failedFontFamily = FontFamily.SansSerif
).resource.resource?.let {
    Text(
        text = "Hello, World",
        fontFamily = LoadedFontFamily(it)
    )
}
Parameters
fontFamily: FontFamily the font family to be loaded
pendingFontFamily: FontFamily? = null an optional resource to be used during loading instead. Only FontFamily that can be loaded synchronously can be used as a pendingFontFamily.
failedFontFamily: FontFamily? = null an optional resource to be used during loading instead. Only FontFamily that can be loaded synchronously can be used as a failedFontFamily.
Exceptions
IllegalArgumentException if FontFamily other than synchronously loadable ones are passed as an argument of pendingFontFamily or failedFontFamily.

loadFontResource

@Composable fun loadFontResource(
    fontFamily: FontFamily,
    pendingTypeface: Typeface? = null,
    failedTypeface: Typeface? = null
): DeferredResource<Typeface>

Load the FontFamily in background thread.

Until font family loading complete, this function returns deferred Typeface with PendingResource. Once loading finishes, recompose is scheduled and this function will return deferred Typeface resource with LoadedResource or FailedResource.

import androidx.compose.material.Text
import androidx.compose.ui.res.fontResource
import androidx.compose.ui.res.loadFontResource
import androidx.compose.ui.text.font.LoadedFontFamily

loadFontResource(
    FontFamily.Default,
    pendingTypeface = fontResource(FontFamily.Cursive),
    failedTypeface = fontResource(FontFamily.SansSerif)
).resource.resource?.let {
    Text(
        text = "Hello, World",
        fontFamily = LoadedFontFamily(it)
    )
}
Parameters
fontFamily: FontFamily the font family to be loaded