常会有这样的需求当点击对话框的外部时,不让对话框消失。
AlertDialog.Builder alert = new AlertDialog.Builder(context, R.style.AlertDialogCustom)
.setTitle(context.getString(R.string.undo_title))
.setIcon(R.drawable.ic_action_help)
.setNegativeButton(R.string.no, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
}).setPositiveButton(R.string.yes, new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int which) {
}
});
AlertDialog alertDialog=alert.create();
<span style="color:#ff0000;">alertDialog.setCanceledOnTouchOutside(false);</span>
alertDialog.show();
红色的代码实现该种需求