在Android中,要在AlertDialog中显示进度条,可以使用ProgressBar组件和AlertDialog.Builder
dialog_progress.xml的文件,并添加以下内容:<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" android:padding="16dp"> <ProgressBar android:id="@+id/progressBar" style="?android:attr/progressBarStyleHorizontal" android:layout_width="match_parent" android:layout_height="wrap_content" android:indeterminate="true" android:max="100"/></LinearLayout>接下来,在你的Activity或Fragment中创建并显示一个包含进度条的AlertDialog。// 使用LayoutInflater实例化自定义布局LayoutInflater inflater = getLayoutInflater();View dialogView = inflater.inflate(R.layout.dialog_progress, null);// 创建一个AlertDialog.BuilderAlertDialog.Builder builder = new AlertDialog.Builder(this);builder.setView(dialogView);// 设置标题和按钮builder.setTitle("正在处理") .setCancelable(false) .setNegativeButton("取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 在这里处理取消操作 } });// 显示AlertDialogAlertDialog alertDialog = builder.create();alertDialog.show();现在,当你运行应用程序时,将显示一个包含进度条的AlertDialog。你可以根据需要自定义布局和对话框的外观。请注意,此示例使用了一个不确定的进度条,但你也可以通过设置android:indeterminate属性为false并更新ProgressBar的进度值来使用确定的进度条。


