how use lottie in custom progress dialog in android studio

3.4k views Asked by At

how can i use lottie animation in custom progress dialog.

i know how implement custom progress bar with lottie but i want progress dialog.

i have my animation in json format. but i dont know how make custom progress dialog. in gradle i write this line

 implementation 'com.airbnb.android:lottie:3.4.4'

and new class

    import android.app.ProgressDialog;
import android.content.Context;
import android.view.animation.Animation;

public class MyProgressDialog extends ProgressDialog {

    public MyProgressDialog(Context context) {
        super(context,R.style.NewDialog);

        // TODO Auto-generated constructor stub
    }

}

i found this video but it is coded by kotlin. i want use java

https://www.youtube.com/watch?v=ZcR6AMNIagU

2

There are 2 answers

2
sara s On

i found solution

1- make one xml layout for new design. "loading.json" is json format of animation in asset folder.

    <?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:orientation="vertical"
    android:layout_width="100dp"
    android:layout_height="100dp"
    >

    <com.airbnb.lottie.LottieAnimationView
        android:id="@+id/progressAnimationView"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_centerInParent="true"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:lottie_autoPlay="true"
        app:lottie_fileName="loading.json"
        app:lottie_loop="true" />

</androidx.constraintlayout.widget.ConstraintLayout>

2-create new java class

public class lottiedialogfragment extends Dialog {
public lottiedialogfragment(Context context) {
    super(context);

    WindowManager.LayoutParams wlmp = getWindow().getAttributes();

    wlmp.gravity = Gravity.CENTER_HORIZONTAL;
    getWindow().setAttributes(wlmp);
    getWindow().setBackgroundDrawable(new ColorDrawable(android.graphics.Color.TRANSPARENT));
    setTitle(null);
    setCancelable(false);
    setOnCancelListener(null);
    View view = LayoutInflater.from(context).inflate(
            R.layout.dialog_lottie, null);
    setContentView(view);
}

}

3-call dialog in main activity

 final lottiedialogfragment lottie=new lottiedialogfragment(this);
    lottie.show();
0
AmrDeveloper On

You can create it easily using the LottieDialog library

Code will be like this

LottieDialog dialog = new LottieDialog(this)
        .setAnimation(R.raw.ripple)
        .setAutoPlayAnimation(true)
        .setDialogHeightPercentage(.2f)
        .setAnimationRepeatCount(LottieDialog.INFINITE)
        .setMessage("Loading...")
        .setMessageColor(orangeColor);

dialog.show();

Github Repo for examples and documentation : LottieDialog

End result will be like this

enter image description here