ProgressDialog 的替代品

Alternate of ProgressDialog

在 API 级别 26 中,ProgressDialog 已弃用。在我的应用程序中,我想用标题和取消选项显示我的下载任务的进度。执行此操作的替代选项是什么。

为什么不在 Dialog

创建自定义布局的情况下将 ProgressView 添加到 Dialog 视图
  LinearLayout linearLayout = new LinearLayout(this);
        linearLayout.setGravity(Gravity.CENTER);
        ProgressBar progressBar = new ProgressBar(this);
        LinearLayout.LayoutParams progressParam = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
        progressParam.setMargins(0, 40, 0, 40);// set margin to progressBar
        progressBar.setLayoutParams(progressParam);
        linearLayout.addView(progressBar);

        AlertDialog.Builder builder = new AlertDialog.Builder(this);
        builder.setTitle("Loading ")
                .setMessage("Please waite until the map loaded")
                .setView(linearLayout).setCancelable(false)
                .setNegativeButton("Cancel", new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        dialog.cancel();     
                    }
                });
                
        builder.create().show();