[英]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.