AlertDialog dialog = new AlertDialog.Builder(this).create();//创建对话框
dialog.setIcon(R.mipmap.ic_launcher);//设置对话框icon dialog.setTitle("这是一个AlertDialog");//设置对话框标题 dialog.setMessage("Hello world");//设置文字显示内容 //分别设置三个button dialog.setButton(DialogInterface.BUTTON_POSITIVE,"确定", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss();//关闭对话框 } }); dialog.setButton(DialogInterface.BUTTON_NEUTRAL,"点我试试", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { } }); dialog.setButton(DialogInterface.BUTTON_NEGATIVE, "取消", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss();//关闭对话框 } }); dialog.show();//显示对话框