如何在 Java 中创建 Lottie 警报对话框

How to create a Lottie Alert Dialog in Java

我尝试搜索有关创建 LottieAlertDialog 的 Java 教程,但我找不到任何内容。它在 Kotlin 中无处不在,但我需要 Java 代码,因为我的项目在 Java.

我试过用这种方式创建我的 LottieAlertDialog

LottieAlertDialog.Builder alert=new LottieAlertDialog.Builder(context,DialogTypes.TYPE_CUSTOM,
                        "social.json") //Here social.json is inside assets folder
                        .setTitle("Social")
                        .setDescription("social");
                alert.build();

但是当我 运行 应用程序时,对话框没有显示。为了检查是否正在创建我的警报对话框,我尝试通过在 Toast:

中打印对话框中设置的描述来测试它
Toast.makeText(context,alert.getDescription(),Toast.LENGTH_SHORT).show();

吐司成功并显示 "social"!这意味着正在创建对话框。但不幸的是它没有显示在我的应用程序中。我该怎么办?我已经实现了所有依赖项,如下所示 link:

lottiealertdialog

这件事与 Kotlin 或 Java 无关,您需要在构建对话框后显示它。到目前为止,您的代码是正确的。你只需要像这样进一步展示它

LottieAlertDialog.Builder alert = new LottieAlertDialog.Builder(context, DialogTypes.TYPE_CUSTOM,
                "social.json")
                .setTitle("Social")
                .setDescription("Social")
                .build()
                .show();

好吧,千辛万苦终于找到了解决办法。这是

alert.build().show();