Skip to content

[MaterialButton] AnimatedVectorDrawable animation not playing inside button #5008

@mardous

Description

@mardous

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
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions