Add interactive Rive animated icons to your Android app using RiveAnimationView and Kotlin state machine controls.
Open your app-level build.gradle and add the Rive Android runtime.
dependencies {
implementation 'app.rive:rive-android:4.1.0'
}Download your icon from Unicorn Icons and place the .riv file in res/raw/. Create the folder if it doesn't exist.
Reference the .riv file and configure the artboard and animation in your XML layout.
<app.rive.runtime.kotlin.RiveAnimationView
android:id="@+id/riveView"
android:layout_width="150dp"
android:layout_height="150dp"
app:riveResource="@raw/your_animation"
app:riveArtboard="Main"
app:riveAnimation="Idle"
app:riveAutoplay="true" />Use the view reference to play, pause, or switch animations and fire state machine inputs.
val riveView = findViewById<RiveAnimationView>(R.id.riveView)
// Play an animation
riveView.play("Idle")
// Pause or switch
riveView.pause()
riveView.setAnimation("Click")
// Fire a state machine trigger
riveView.fireState("State Machine 1", "Trigger")