如何在没有 XML 的情况下在 AlertDialog Builder 中显示进度条以及其他元素?

发布于 2024-11-25 02:16:06 字数 1684 浏览 0 评论 0原文

我正在尝试在 Android 手机中触摸传输通知后为蓝牙传输创建一个 AlertDialog。

我正在尝试这样的事情: 从下面,我得到了一切——图标、标题和两个按钮。我确信我可以在 AlertDialog.Builder 属性的帮助下使用游标添加其他信息,例如 From、FileName 等。我只是不知道其中是否有进度条。我不想使用 XML。

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setIcon(R.id.imageFile);
    alertDialogBuilder.setTitle("File Transfer");

    ProgressDialog progressDialog;
    Context mContext = null;
    progressDialog = new ProgressDialog(mContext);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    //alertDialogBuilder.setView(progressDialog); //STUCK HERE
    //"!" icon and "File Transfer"
    //from : device name
    //File: <name>
    //Type: <type> (<size>)
    //Receiving/Sending File
    //<%> | Green progress bar
    //Hide and Stop buttons

    alertDialogBuilder.setPositiveButton("STOP", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    alertDialogBuilder.setNegativeButton("HIDE", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    return alertDialog;

}

我已经准备好了一切,只是我无法弄清楚如何在此处添加进度条。

我可以使用 XML 布局获取进度条并用作

alertDialogBu​​ilder.setView(R.id.what-ever-xml-file) 或者如何在 Java 文件本身中为该进度条创建一个视图,并将进度条放入该视图中,然后将该视图放入对话框中。

我想要这样的东西:

Alert Dialog with ProgressBar

I am trying to create an AlertDialog for a Bluetooth transfer after the transfer notification is touched in an android phone.

I am trying something like this:
Out of the below, I am getting everything - icon, title and two buttons. I am sure I can add other info like From, FileName and others using cursors with the help AlertDialog.Builder properties. I just do not know to get a progress-bar in it. I do not want to use an XML.

protected Dialog onCreateDialog(int id) {
    AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(this);
    alertDialogBuilder.setIcon(R.id.imageFile);
    alertDialogBuilder.setTitle("File Transfer");

    ProgressDialog progressDialog;
    Context mContext = null;
    progressDialog = new ProgressDialog(mContext);
    progressDialog.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);

    //alertDialogBuilder.setView(progressDialog); //STUCK HERE
    //"!" icon and "File Transfer"
    //from : device name
    //File: <name>
    //Type: <type> (<size>)
    //Receiving/Sending File
    //<%> | Green progress bar
    //Hide and Stop buttons

    alertDialogBuilder.setPositiveButton("STOP", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    alertDialogBuilder.setNegativeButton("HIDE", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int id) {
            dialog.cancel();
        }
    });
    AlertDialog alertDialog = alertDialogBuilder.create();
    return alertDialog;

}

I have everything in place except I am not able to figure out how to bring a progress-bar here.

Can I getjust a progress-bar using XML layout and use as

alertDialogBuilder.setView(R.id.what-ever-xml-file)
Or how to create a view for that progress-bar in he Java file itself and put a progressbar in that view and then put that view inside the dialog.

I want sth like this:

Alert Dialog with ProgressBar

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花想c 2024-12-02 02:16:06

您可以使用 Dialog 并使用 _dialog.addContentView(view, params) 方法在其上添加 ProgressBar

You can use Dialog and add ProgressBar on this by using

_dialog.addContentView(view, params) method.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文