我发现ProgressDialog现在已经被弃用了。除了ProgressBar,还有什么替代工具可以代替它。 我使用的是android studio 2.3.3版。

ProgressDialog progressDialog=new ProgressDialog(this);
progressDialog.show();

当前回答

你可以使用wasabeef库来使用SpotDialog,你可以从下面的链接找到完整的教程:

Android中的SpotsDialog示例

其他回答

ProgressBar是ProgressDialog的最佳选择。 指示操作进度的用户界面元素。

欲了解更多信息,请参阅谷歌文档:https://developer.android.com/reference/android/widget/ProgressBar.html

我使用来自https://github.com/Q115/DelayedProgressDialog的DelayedProgressDialog,它与ProgressDialog相同,在必要时具有延迟的额外好处。

使用它类似于Android O之前的ProgressDialog:

DelayedProgressDialog progressDialog = new DelayedProgressDialog();
progressDialog.show(getSupportFragmentManager(), "tag");

创建一个带有进度条和其他视图的xml文件,并使用此xml文件或Alertdialog派生类扩展派生Dialog类视图。在其他解决方案中已详细提供。 但是如果你想要一个解或者存在的库。我找到了这两个。

https://github.com/Livin21/MissMe https://github.com/skydoves/ProgressView

这些都是完美的,而且是根据需要来做的。

使用这个简单的技巧

/ /初始化

val dialog : Dialog = Dialog(this)

/ /设置布局

dialog.setContentView(R.layout.view_loading)

/ /显示对话框

dialog.show()

//删除白色背景

dialog.window.setbackgroundDrawable(ColorDrawable(0))

下面是我的不确定进度对话框版本:

layout_loading_dialog.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="horizontal"
    android:padding="20dp">

    <ProgressBar
        android:id="@+id/progressBar"
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginEnd="10dp"
        android:layout_marginRight="10dp"
        android:layout_weight="1" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="match_parent"
        android:layout_weight="4"
        android:gravity="center"
        android:textAlignment="textStart"
        android:id="@+id/message"
        tools:text="Please wait..." />
</LinearLayout>

IndeterminateProgressDialog.kt:

class IndeterminateProgressDialog(context: Context) : AlertDialog(context) {
    private val messageTextView: TextView

    init {
        val view = LayoutInflater.from(context).inflate(R.layout.layout_loading_dialog, null)
        messageTextView = view.findViewById(R.id.message)
        setView(view)
    }

    override fun setMessage(message: CharSequence?) {
        this.messageTextView.text = message.toString()
    }

}

用法:

   val dialog = IndeterminateProgressDialog(context)
                    dialog.setMessage("Please wait...")
                    dialog.setCanceledOnTouchOutside(false)
                    dialog.setCancelable(false)
                    dialog.show()