在android中创建自定义警报对话框时出错

在android中创建自定义警报对话框时出错,android,android-alertdialog,Android,Android Alertdialog,在Android应用程序中创建自定义警报对话框时,我遇到以下错误 错误 requestFeature() must be called before adding content 以下是我创建自定义警报对话框的代码 代码 AlertDialog alertDialog=new AlertDialog.Builder(home.this).create(); alertDialog.setTitle("Title here.."); alertDialog.setContentView(R.la

Android
应用程序中创建自定义
警报对话框时,我遇到以下错误

错误

requestFeature() must be called before adding content
以下是我创建自定义警报对话框的代码

代码

AlertDialog alertDialog=new AlertDialog.Builder(home.this).create();
alertDialog.setTitle("Title here..");
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show(); 
从第一行删除.create()。

从第一行删除.create()。

从第一行删除.create()。

从第一行删除.create()。

将此作为指南:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    YourActivity.this);

alertDialogBuilder.setTitle("Your title here...");

alertDialogBuilder
        .setMessage("Your message here...")
        .setCancelable(false)
        .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                // Your works
                }
            })
        .setNegativeButton("No",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                dialog.cancel();
            }
        });

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();
将此作为指南:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    YourActivity.this);

alertDialogBuilder.setTitle("Your title here...");

alertDialogBuilder
        .setMessage("Your message here...")
        .setCancelable(false)
        .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                // Your works
                }
            })
        .setNegativeButton("No",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                dialog.cancel();
            }
        });

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();
将此作为指南:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    YourActivity.this);

alertDialogBuilder.setTitle("Your title here...");

alertDialogBuilder
        .setMessage("Your message here...")
        .setCancelable(false)
        .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                // Your works
                }
            })
        .setNegativeButton("No",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                dialog.cancel();
            }
        });

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();
将此作为指南:

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(
                    YourActivity.this);

alertDialogBuilder.setTitle("Your title here...");

alertDialogBuilder
        .setMessage("Your message here...")
        .setCancelable(false)
        .setPositiveButton("Yes",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                // Your works
                }
            })
        .setNegativeButton("No",new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int id) {
                dialog.cancel();
            }
        });

AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();

此处是自定义对话框的代码段:

使用新对话框而不是DialogBuilder

Dialog d = new Dialog(MainActivity.this);
        d.setContentView(R.layout.dialog);
        d.setTitle("This is custom dialog box");
        d.show();   

此处是自定义对话框的代码段:

使用新对话框而不是DialogBuilder

Dialog d = new Dialog(MainActivity.this);
        d.setContentView(R.layout.dialog);
        d.setTitle("This is custom dialog box");
        d.show();   

此处是自定义对话框的代码段:

使用新对话框而不是DialogBuilder

Dialog d = new Dialog(MainActivity.this);
        d.setContentView(R.layout.dialog);
        d.setTitle("This is custom dialog box");
        d.show();   

此处是自定义对话框的代码段:

使用新对话框而不是DialogBuilder

Dialog d = new Dialog(MainActivity.this);
        d.setContentView(R.layout.dialog);
        d.setTitle("This is custom dialog box");
        d.show();   
试试这个:

试试这个:

试试这个:

试试这个:


你能发布整个片段吗?你能发布整个片段吗?你能发布整个片段吗?你能发布整个片段吗?