RiveAnimationView handles rendering. fireState() in Kotlin triggers the Hover and Click animations.
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 put the .riv file in app/src/main/res/raw/. Create the folder if it doesn't exist.
Reference the file and configure the artboard and animation in XML.
<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" />Get the view by ID and use fireState() or setBooleanState() to trigger the Hover and Click animations.
val riveView = findViewById<RiveAnimationView>(R.id.riveView)
// Play an animation
riveView.play("Idle")
// Fire the click trigger
riveView.fireState("State Machine 1", "Clicked")
// Set hover on touch down/up
riveView.setBooleanState("State Machine 1", "Hover", true) // touch down
riveView.setBooleanState("State Machine 1", "Hover", false) // touch upWhere does the .riv file go?
In app/src/main/res/raw/. Reference it as @raw/filename in XML, without the extension.
How do I trigger hover on touch?
Use a touch listener — call setBooleanState("State Machine 1", "Hover", true) on ACTION_DOWN, then false on ACTION_UP.
Can I load from a URL?
Yes. Use riveView.setRiveUrl(url) with INTERNET permission in your manifest.
Get your animated icons
Browse icons ready for Android — free to download.