常会有这样的需求当点击对话框的外部时,不让对话框消失。
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();红色的代码实现该种需求
本文介绍了一种方法,即如何防止Android中的AlertDialog在点击其外部区域时被关闭。通过设置`alertDialog.setCanceledOnTouchOutside(false)`可以实现这一功能。
1172

被折叠的 条评论
为什么被折叠?



