androidのdialog点击按钮不关闭

2022-08-16 17:03:33 浏览数 (1)

智慧是宝石,如果用谦虚镶边,就会更加灿烂夺目。——高尔基

如果想要安卓的dialog点击按钮后默认不关闭弹框,可以这么写

代码语言:javascript复制
AlertDialog.Builder builder = new AlertDialog.Builder(context);
            AlertDialog alertDialog = builder.setPositiveButton("保存", null)
                    .setNegativeButton("收藏", (dialog, which) -> {
                        ToastUtils.shortToast("我还没做收藏功能!");
                    }).create();
            alertDialog.show();
            alertDialog.getButton(AlertDialog.BUTTON_POSITIVE).setOnClickListener(v1 -> {
                RestVolleyDownload.DownloadResponse response = RestVolleyDownload.syncDownload(context, url, url.substring(url.lastIndexOf("/")   1));
                System.out.println(response);
                ToastUtils.shortToast("保存成功");
            });

0 人点赞