Add Lottie animated icons to your Android app using the official Airbnb Lottie library for Kotlin.
Open your app-level build.gradle and add the Lottie dependency.
dependencies {
implementation 'com.airbnb.android:lottie:6.0.0'
}Download your icon from Unicorn Icons and place the .json file in app/src/main/res/raw/. Create the folder if it doesn't exist.
Reference the animation file using app:lottie_rawRes in your XML layout.
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/lottieIcon"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_gravity="center"
app:lottie_rawRes="@raw/your_animation"
app:lottie_autoPlay="true"
app:lottie_loop="true"
app:lottie_speed="1.0" />Use the view reference to play, pause, or swap animations at runtime.
val animationView = findViewById<LottieAnimationView>(R.id.lottieIcon)
animationView.setAnimation(R.raw.your_animation)
animationView.playAnimation()
// animationView.pauseAnimation()
// animationView.cancelAnimation()