没有按钮的Android对话框

use*_*745 13 android

我可以创建一个没有负或正按钮的对话框.具体行动后,它会自我毁灭吗?

 AlertDialog.Builder dialog_detect= new AlertDialog.Builder(MainActivity.this);
 dialog.setTitle("Detecting.....");
 dialog.setMessage("Please Wait");
 dialog.show();
Run Code Online (Sandbox Code Playgroud)

cro*_*boy 14

你可以很容易地做到这一点.

AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(context);

// set title
alertDialogBuilder.setTitle("Your Title");

// set dialog message
alertDialogBuilder.setMessage("Message here!").setCancelable(false);

// create alert dialog
AlertDialog alertDialog = alertDialogBuilder.create();

// show it
alertDialog.show();

// After some action
alertDialog.dismiss();
Run Code Online (Sandbox Code Playgroud)

如果你有AlertDialog其他地方的参考,你仍然可以打电话alertDialog.dismiss().这将关闭对话框.