通过使用以下代码,我的活动中有一个带有 OK 按钮的 AlertDialog:
alertDialog = new AlertDialog.Builder(getApplicationContext()).create();
//Setting Dialog Title
alertDialog.setTitle("Alert Dialog");
// Setting Dialog Message
alertDialog.setMessage("Welcome to AndroidHive.info");
// Setting Icon to Dialog
alertDialog.setIcon(R.drawable.icon);
// Setting OK Button
alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Write your code here to execute after dialog closed
}
});
alertDialog.show();
这在应用程序中运行良好,但我希望即使我们在应用程序之外也能运行并显示它。当然,应用程序仍在运行且未关闭。很像吐司。即使我可以使用带有 OK 按钮的 Toast,我也会很高兴。
任何帮助表示赞赏。谢谢。