'Lottie Animation - Switch Button goes back to starting state - Android Studio
I'm trying to recreate a switch button using Lottie Animations and it does work good on click (when clicked), but goes back to the original state instantly. I have disabled AutoPlay and Loop as well in XML.
Here is the code :
LottieAnimationView dayandnight = (LottieAnimationView) findViewById(R.id.dayandnight);
dayandnight.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
if (isSwitchOn){
dayandnight.setMinAndMaxFrame(0,68);
dayandnight.playAnimation();
isSwitchOn = true;
//AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_YES);
}
else
dayandnight.setMinAndMaxFrame(68,141);
dayandnight.playAnimation();
isSwitchOn = false;
//AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO);
}
});
Here is the XML code for the above Lottie Animation:
<com.airbnb.lottie.LottieAnimationView
android:id="@+id/dayandnight"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="15dp"
app:lottie_loop="false"
app:lottie_autoPlay="false"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent"
android:contentDescription="@string/day_and_night_switch"
app:lottie_rawRes="@raw/dayandnight" />
Every suggestion will be a great asset for my project! Thank you
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
