AnimatedVectorDrawableCompat

open class AnimatedVectorDrawableCompat : VectorDrawableCommon, Animatable2Compat
androidx.vectordrawable.graphics.drawable.AnimatedVectorDrawableCompat

For API 24 and above, this class is delegating to the framework's . For older API version, this class uses android.animation.ObjectAnimator and android.animation.AnimatorSet to animate the properties of a to create an animated drawable.

AnimatedVectorDrawableCompat are defined in the same XML format as AnimatedVectorDrawable.

Here are all the animatable attributes in VectorDrawableCompat: Element Name Animatable attribute name <vector> alpha <group> rotation pivotX pivotY scaleX scaleY translateX translateY <path> fillColor pathData strokeColor strokeWidth strokeAlpha fillAlpha trimPathStart trimPathEnd trimPathOffset

You can always create a AnimatedVectorDrawableCompat object and use it as a Drawable by the Java API. In order to refer to AnimatedVectorDrawableCompat inside a XML file, you can use app:srcCompat attribute in AppCompat library's ImageButton or ImageView.

Note that the animation in AnimatedVectorDrawableCompat now can support the following features:
  • Path Morphing (PathType evaluator). This is used for morphing one path into another.
  • Path Interpolation. This is used to defined a flexible interpolator (represented as a path) instead of the system defined ones like LinearInterpolator.
  • Animating 2 values in one ObjectAnimator according to one path's X value and Y value. One usage is moving one object in both X and Y dimensions along an path.

Summary

Public methods
open Boolean

open Unit
draw(canvas: Canvas!)

open Unit

open Int

open Unit
setAlpha(alpha: Int)

open Unit
setTint(tint: Int)

open ColorFilter!

open Unit

open Int

open Boolean
setVisible(visible: Boolean, restart: Boolean)

open Unit
setTintMode(tintMode: Mode!)

open Unit

open Unit
inflate(res: Resources!, parser: XmlPullParser!, attrs: AttributeSet!, theme: Theme!)

open Unit
inflate(res: Resources!, parser: XmlPullParser!, attrs: AttributeSet!)

open Unit

open Unit

open Int

open Boolean

open Drawable!

mutate() will be effective only if the getConstantState() is returning non-null.

open Int

open Int

open Unit

open Boolean

open Boolean

open Unit
setColorFilter(colorFilter: ColorFilter!)

open ConstantState!

Note that we don't support constant state when SDK < 24.

open Boolean

open Unit

open static AnimatedVectorDrawableCompat?
create(@NonNull context: Context, @DrawableRes resId: Int)

Create a AnimatedVectorDrawableCompat object.

open static AnimatedVectorDrawableCompat!
createFromXmlInner(context: Context!, r: Resources!, parser: XmlPullParser!, attrs: AttributeSet!, theme: Theme!)

Create a AnimatedVectorDrawableCompat from inside an XML document using an optional Theme.

open static Unit

Utility function to register callback to Drawable, when the drawable is created from XML and referred in Java code, e.

open static Boolean

Utility function to unregister animation callback from Drawable, when the drawable is created from XML and referred in Java code, e.

open static Unit

Utility function to clear animation callbacks from Drawable, when the drawable is created from XML and referred in Java code, e.

Protected methods
open Boolean

open Unit
onBoundsChange(bounds: Rect!)

open Boolean

Public methods

canApplyTheme

open fun canApplyTheme(): Boolean

draw

open fun draw(canvas: Canvas!): Unit

start

open fun start(): Unit

getAlpha

open fun getAlpha(): Int

setAlpha

open fun setAlpha(alpha: Int): Unit

setTint

open fun setTint(tint: Int): Unit

getColorFilter

open fun getColorFilter(): ColorFilter!

setAutoMirrored

open fun setAutoMirrored(mirrored: Boolean): Unit

getOpacity

open fun getOpacity(): Int

setVisible

open fun setVisible(visible: Boolean, restart: Boolean): Boolean

setTintMode

open fun setTintMode(tintMode: Mode!): Unit

applyTheme

open fun applyTheme(t: Theme!): Unit

inflate

open fun inflate(res: Resources!, parser: XmlPullParser!, attrs: AttributeSet!, theme: Theme!): Unit

inflate

open fun inflate(res: Resources!, parser: XmlPullParser!, attrs: AttributeSet!): Unit

stop

open fun stop(): Unit

clearAnimationCallbacks

open fun clearAnimationCallbacks(): Unit

getIntrinsicWidth

open fun getIntrinsicWidth(): Int

isRunning

open fun isRunning(): Boolean

mutate

open fun mutate(): Drawable!

mutate() will be effective only if the getConstantState() is returning non-null. Otherwise, it just return the current object without modification.

getIntrinsicHeight

open fun getIntrinsicHeight(): Int

getChangingConfigurations

open fun getChangingConfigurations(): Int

registerAnimationCallback

open fun registerAnimationCallback(@NonNull callback: Animatable2Compat.AnimationCallback): Unit

unregisterAnimationCallback

open fun unregisterAnimationCallback(@NonNull callback: Animatable2Compat.AnimationCallback): Boolean

isStateful

open fun isStateful(): Boolean

setColorFilter

open fun setColorFilter(colorFilter: ColorFilter!): Unit

getConstantState

open fun getConstantState(): ConstantState!

Note that we don't support constant state when SDK < 24. Make sure you check the return value before using it.

isAutoMirrored

open fun isAutoMirrored(): Boolean

setTintList

open fun setTintList(tint: ColorStateList!): Unit

create

@Nullable open static fun create(@NonNull context: Context, @DrawableRes resId: Int): AnimatedVectorDrawableCompat?

Create a AnimatedVectorDrawableCompat object.

Parameters
context Context: the context for creating the animators.
resId Context: the resource ID for AnimatedVectorDrawableCompat object.
Return
AnimatedVectorDrawableCompat?: a new AnimatedVectorDrawableCompat or null if parsing error is found.

createFromXmlInner

open static fun createFromXmlInner(context: Context!, r: Resources!, parser: XmlPullParser!, attrs: AttributeSet!, theme: Theme!): AnimatedVectorDrawableCompat!

Create a AnimatedVectorDrawableCompat from inside an XML document using an optional Theme. Called on a parser positioned at a tag in an XML document, tries to create a Drawable from that tag. Returns null if the tag is not a valid drawable.

registerAnimationCallback

open static fun registerAnimationCallback(dr: Drawable!, callback: Animatable2Compat.AnimationCallback!): Unit

Utility function to register callback to Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable(). From API 24 on, the drawable is treated as an AnimatedVectorDrawable. Otherwise, it is treated as AnimatedVectorDrawableCompat.

unregisterAnimationCallback

open static fun unregisterAnimationCallback(dr: Drawable!, callback: Animatable2Compat.AnimationCallback!): Boolean

Utility function to unregister animation callback from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable(). From API 24 on, the drawable is treated as an AnimatedVectorDrawable. Otherwise, it is treated as AnimatedVectorDrawableCompat.

clearAnimationCallbacks

open static fun clearAnimationCallbacks(dr: Drawable!): Unit

Utility function to clear animation callbacks from Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable(). From API 24 on, the drawable is treated as an AnimatedVectorDrawable. Otherwise, it is treated as AnimatedVectorDrawableCompat.

Protected methods

onLevelChange

protected open fun onLevelChange(level: Int): Boolean

onBoundsChange

protected open fun onBoundsChange(bounds: Rect!): Unit

onStateChange

protected open fun onStateChange(state: IntArray!): Boolean