[英]Error while creating custom Alert Dialog in android
在Android
应用程序中创建自定义Alert Dialog
时,出现以下错误。
错误
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();
自定义对话框的代码段如下:
使用新的Dialog而不是DialogBuilder
Dialog d = new Dialog(MainActivity.this);
d.setContentView(R.layout.dialog);
d.setTitle("This is custom dialog box");
d.show();
从第一行删除.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(home.this);
alertDialogBuilder.setTitle("Title here..");
alertDialogBuilder.setContentView(R.layout.custom_alertdialog);
AlertDialog alertDialog = alertDialogBuilder.create();
alertDialog.show();
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.