其他分享
首页 > 其他分享> > Android如何创建并展示对话框

Android如何创建并展示对话框

作者:互联网

普通对话框的创建

初始化方法

 public Dialog onCreateDialog(User user) {
        // Use the Builder class for convenient dialog construction
        AlertDialog.Builder builder = new AlertDialog.Builder(MainActivity.this);
        builder.setMessage("确认删除?")
                .setPositiveButton("确定", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // FIRE ZE MISSILES!
                        dao.delete(user);
                        onCreate(null);//刷新界面
                    }
                })
                .setNegativeButton("取消", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int id) {
                        // User cancelled the dialog
                    }
                });
        // Create the AlertDialog object and return it
        return builder.create();
    }

调用该方法创造对话框

onCreateDialog(user).show();

效果展示

image

标签:展示,Builder,对话框,DialogInterface,dialog,new,Android,public
来源: https://www.cnblogs.com/java-six/p/15863319.html