{% setvar book_path %}/reference/androidx/_book.yaml{% endsetvar %} {% include "_shared/_reference-head-tags.html" %}

AnimatedImageVector.Companion

public static class AnimatedImageVector.Companion


Provide an empty companion object to hang platform-specific companion extensions onto.

Summary

Extension functions

static final @NonNull AnimatedImageVector

Load an AnimatedImageVector from an Android resource id.

Extension functions

AnimatedVectorResourcesKt.animatedVectorResource

@ExperimentalAnimationGraphicsApi
@Composable
public static final @NonNull AnimatedImageVector AnimatedVectorResourcesKt.animatedVectorResource(
    @NonNull AnimatedImageVector.Companion receiver,
    @DrawableRes int id
)

Load an AnimatedImageVector from an Android resource id.

import androidx.annotation.DrawableRes
import androidx.compose.animation.graphics.ExperimentalAnimationGraphicsApi
import androidx.compose.animation.graphics.res.animatedVectorResource
import androidx.compose.animation.graphics.res.rememberAnimatedVectorPainter
import androidx.compose.animation.graphics.vector.AnimatedImageVector
import androidx.compose.foundation.Image
import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.size
import androidx.compose.runtime.Composable
import androidx.compose.runtime.mutableStateOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp

@OptIn(ExperimentalAnimationGraphicsApi::class)
@Composable
fun AnimatedVector(@DrawableRes drawableId: Int) {
    val image = AnimatedImageVector.animatedVectorResource(drawableId)
    var atEnd by remember { mutableStateOf(false) }
    Image(
        painter = rememberAnimatedVectorPainter(image, atEnd),
        contentDescription = "Your content description",
        modifier = Modifier.size(64.dp).clickable {
            atEnd = !atEnd
        }
    )
}
Parameters
@DrawableRes int id

the resource identifier

Returns
@NonNull AnimatedImageVector

an animated vector drawable resource.