简体   繁体   English

ProgressDialog 的替代

[英]Alternate of ProgressDialog

In API level 26, ProgressDialog is deprecated.在 API 级别 26 中,不推荐使用 ProgressDialog。 In my app I want to show the progress of my downloading task with title and cancel option.在我的应用程序中,我想显示带有标题和取消选项的下载任务的进度。 What would be the alternate option to do this.这样做的替代选择是什么。

Why not adding a ProgressView to your Dialog view without creating a custom layout for Dialog为什么不在为 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();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM