-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Open
Labels
Description
Description:
The animation of an AnimatedVectorDrawable (AVD) does not play when set as an icon in a MaterialButton. While the icon renders correctly in its initial state, any calls to start() on the drawable do not reflect in the UI, or the animation fails to trigger entirely.
Steps to Reproduce:
- Create an AnimatedVectorDrawable XML.
- Set it as the icon of a MaterialButton using app:icon.
- Reference the icon in code:
val drawable = button.icon as? AnimatedVectorDrawable. - Call
drawable?.start().
Expected Behavior:
The icon should play its animation sequence.
Actual Behavior:
The icon remains static.
Example Code:
val iconRes = if (withAnimation) {
if (isFavorite) R.drawable.avd_favorite else R.drawable.avd_unfavorite
} else {
if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_outline_24dp
}
val iconRes = if (isFavorite) R.drawable.ic_favorite_24dp else R.drawable.ic_favorite_outline_24dp
icon = ContextCompat.getDrawable(context, iconRes).also { drawable ->
if (drawable is AnimatedVectorDrawable) {
drawable.start() // this does nothing
}
}Reactions are currently unavailable