我的代码在下面,并且当onCreate()
我从没有错误或stracktrace 调用时工作得非常好.它只是没有显示.
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setMessage("Are you sure you want to exit?")
.setCancelable(false)
.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
finish();
}
})
.setNegativeButton("No", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int id) {
dialog.cancel();
}
});
AlertDialog alert = builder.create();
alert.show();
Run Code Online (Sandbox Code Playgroud)
尝试..
AlertDialog.Builder dlgAlert = new AlertDialog.Builder(this);
dlgAlert.setMessage("This is an alert with no consequence");
dlgAlert.setTitle("App Title");
dlgAlert.setPositiveButton("OK", null);
dlgAlert.setCancelable(true);
dlgAlert.create().show();
Run Code Online (Sandbox Code Playgroud)
在代码中的构建器上调用 .show() 。
| 归档时间: |
|
| 查看次数: |
1920 次 |
| 最近记录: |