AnimatedVectorDrawableCompat

class AnimatedVectorDrawableCompat : Drawable, Animatable2Compat


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 VectorDrawableCompat 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
alpha
rotation
pivotX
pivotY
scaleX
scaleY
translateX
translateY
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 functions

Unit
Boolean
Unit

Removes all existing animation callbacks.

java-static 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().

Unit
java-static AnimatedVectorDrawableCompat?
create(context: Context, resId: @DrawableRes Int)

Create a AnimatedVectorDrawableCompat object.

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

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

Unit
draw(canvas: Canvas!)
Int
Int
ColorFilter!
Drawable.ConstantState!

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

Drawable!
Int
Int
Int
Int
Int

This function is deprecated.

Boolean
getPadding(padding: Rect!)
IntArray<Int>!
Region!
Unit
inflate(res: Resources!, parser: XmlPullParser!, attrs: AttributeSet!)
Unit
inflate(
    res: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!,
    theme: Resources.Theme!
)
Boolean
Boolean
Boolean
Unit
Drawable!

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

Unit

Adds a callback to listen to the animation events.

java-static Unit

Utility function to register callback to Drawable, when the drawable is created from XML and referred in Java code, e.g: ImageView.getDrawable().

Unit
setAlpha(alpha: Int)
Unit
Unit
Unit
setColorFilter(colorFilter: ColorFilter!)
Unit

This function is deprecated.

Unit
Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Boolean
setState(stateSet: IntArray!)
Unit
setTint(tint: Int)
Unit
Unit
Boolean
setVisible(visible: Boolean, restart: Boolean)
Unit
Unit
Boolean

Removes the specified animation callback.

java-static 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().

Protected functions

Unit
onBoundsChange(bounds: Rect!)
Boolean
Boolean

Inherited functions

From android.graphics.drawable.Drawable
Unit
Unit
Rect!
Unit
copyBounds(bounds: Rect!)
java-static Drawable!
createFromPath(pathName: String!)
java-static Drawable!
createFromResourceStream(
    res: Resources!,
    value: TypedValue!,
    is: InputStream!,
    srcName: String!
)
java-static Drawable!
createFromStream(is: InputStream!, srcName: String!)
java-static Drawable!
java-static Drawable!
createFromXmlInner(
    r: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!
)
Rect!
Drawable.Callback!
Drawable!
Rect!
Unit
Int
Int
Int
Int
Insets!
Unit
getOutline(outline: Outline!)
Boolean
getPadding(padding: Rect!)
IntArray<Int>!
Region!
Boolean
Unit
Boolean
Boolean
Boolean
Unit
Unit
onBoundsChange(bounds: Rect!)
Boolean
onLayoutDirectionChanged(layoutDirection: Int)
Boolean
java-static Int
resolveOpacity(op1: Int, op2: Int)
Unit
scheduleSelf(what: Runnable!, when: Long)
Unit
setBounds(left: Int, top: Int, right: Int, bottom: Int)
Unit
Unit
Unit
setDither(dither: Boolean)

This function is deprecated.

Unit
Unit
Unit
setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int)
Boolean
setLayoutDirection(layoutDirection: Int)
Boolean
setLevel(level: Int)
Boolean
setState(stateSet: IntArray!)
Unit
Unit

Public functions

applyTheme

fun applyTheme(t: Resources.Theme!): Unit

canApplyTheme

fun canApplyTheme(): Boolean

clearAnimationCallbacks

Added in 1.2.0-rc01
fun clearAnimationCallbacks(): Unit

Removes all existing animation callbacks.

clearAnimationCallbacks

Added in 1.0.0
java-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.

clearColorFilter

fun clearColorFilter(): Unit

create

Added in 1.0.0
java-static fun create(context: Context, resId: @DrawableRes Int): AnimatedVectorDrawableCompat?

Create a AnimatedVectorDrawableCompat object.

Parameters
context: Context

the context for creating the animators.

resId: @DrawableRes Int

the resource ID for AnimatedVectorDrawableCompat object.

Returns
AnimatedVectorDrawableCompat?

a new AnimatedVectorDrawableCompat or null if parsing error is found.

createFromXmlInner

Added in 1.0.0
java-static fun createFromXmlInner(
    context: Context!,
    r: Resources!,
    parser: XmlPullParser!,
    attrs: AttributeSet!,
    theme: Resources.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.

draw

Added in 1.0.0
fun draw(canvas: Canvas!): Unit

getAlpha

fun getAlpha(): Int

getChangingConfigurations

fun getChangingConfigurations(): Int

getColorFilter

fun getColorFilter(): ColorFilter!

getConstantState

fun getConstantState(): Drawable.ConstantState!

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

getCurrent

fun getCurrent(): Drawable!

getIntrinsicHeight

fun getIntrinsicHeight(): Int

getIntrinsicWidth

fun getIntrinsicWidth(): Int

getMinimumHeight

fun getMinimumHeight(): Int

getMinimumWidth

fun getMinimumWidth(): Int

getOpacity

Added in 1.0.0
fun getOpacity(): Int

getPadding

fun getPadding(padding: Rect!): Boolean

getState

fun getState(): IntArray<Int>!

getTransparentRegion

fun getTransparentRegion(): Region!

inflate

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

isAutoMirrored

fun isAutoMirrored(): Boolean

isRunning

Added in 1.0.0
fun isRunning(): Boolean

isStateful

fun isStateful(): Boolean

jumpToCurrentState

fun jumpToCurrentState(): Unit

mutate

fun mutate(): Drawable!

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

registerAnimationCallback

Added in 1.2.0-rc01
fun registerAnimationCallback(
    callback: Animatable2Compat.AnimationCallback
): Unit

Adds a callback to listen to the animation events.

Parameters
callback: Animatable2Compat.AnimationCallback

Callback to add.

registerAnimationCallback

Added in 1.0.0
java-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.

setAlpha

Added in 1.0.0
fun setAlpha(alpha: Int): Unit

setAutoMirrored

fun setAutoMirrored(mirrored: Boolean): Unit

setChangingConfigurations

fun setChangingConfigurations(configs: Int): Unit

setColorFilter

Added in 1.0.0
fun setColorFilter(colorFilter: ColorFilter!): Unit

setColorFilter

Added in 1.0.0
fun setColorFilter(color: Int, mode: PorterDuff.Mode!): Unit

setFilterBitmap

fun setFilterBitmap(filter: Boolean): Unit

setHotspot

fun setHotspot(x: Float, y: Float): Unit

setHotspotBounds

fun setHotspotBounds(left: Int, top: Int, right: Int, bottom: Int): Unit

setState

fun setState(stateSet: IntArray!): Boolean

setTint

fun setTint(tint: Int): Unit

setTintList

fun setTintList(tint: ColorStateList!): Unit

setTintMode

fun setTintMode(tintMode: PorterDuff.Mode!): Unit

setVisible

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

start

Added in 1.0.0
fun start(): Unit

stop

Added in 1.0.0
fun stop(): Unit

unregisterAnimationCallback

Added in 1.2.0-rc01
fun unregisterAnimationCallback(
    callback: Animatable2Compat.AnimationCallback
): Boolean

Removes the specified animation callback.

Parameters
callback: Animatable2Compat.AnimationCallback

Callback to remove.

Returns
Boolean

false if callback didn't exist in the call back list, or true if callback has been removed successfully.

unregisterAnimationCallback

Added in 1.0.0
java-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.

Protected functions

onBoundsChange

protected fun onBoundsChange(bounds: Rect!): Unit

onLevelChange

protected fun onLevelChange(level: Int): Boolean

onStateChange

protected fun onStateChange(state: IntArray!): Boolean