我在Alert Dialog
应用程序中创建自定义Android
时收到以下错误。
错误
requestFeature() must be called before adding content
以下是我自定义Alert Dialog
创建的代码。
代码
AlertDialog alertDialog=new AlertDialog.Builder(home.this).create();
alertDialog.setTitle("Title here..");
alertDialog.setContentView(R.layout.custom_alertdialog);
alertDialog.show();
答案 0 :(得分:2)
自定义对话框的代码段:
使用新的Dialog而不是DialogBuilder
Dialog d = new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("This is custom dialog box");
d.show();
答案 1 :(得分:1)
从第一行删除.create()。
答案 2 :(得分:0)
以此为指导:
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();
答案 3 :(得分:0)
试试这个:
AlertDialog.Builder alertDialogBuilder=new AlertDialog.Builder(home.this);
alertDialogBuilder.setTitle("Title here..");
alertDialogBuilder.setContentView(R.layout.custom_alertdialog);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();