new AlertDialog.Builder(activity)
.setView(view)
.setCancelable(false)
.setTitle("登陆系统")
.setPositiveButton("登录", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialog, int i) {
EditText userName = (EditText) view.findViewById(R.id.editText);
EditText userpwd = (EditText) view.findViewById(R.id.editText1);
try {
if (userName == null || userName.getText().toString().trim().length() == 0) {
//不关闭对话框
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, false); //设定为false,则不可以关闭对话框
dialog.dismiss();
ToastUtils.show(activity, "没有输入用户名......");
} else if (userpwd == null || userpwd.getText().toString().trim().length() == 0) {
//不关闭对话框
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, false); //设定为false,则不可以关闭对话框
dialog.dismiss();
ToastUtils.show(activity, "没有输入密码......");
} else {
// 要正常关闭对话框
ToastUtils.show(activity, "登陆成功......");
Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);//设定为true,则可以关闭对话框
dialog.dismiss();
}
} catch (Exception e) {
}
}
})
.setNegativeButton("取消", new DialogInterface.OnClickListener() {
@Override
public void onClick(DialogInterface dialogInterface, int i) {
activity.finish();
}
}
)
.create()
.show();
可以关闭:
[color=darkblue]field.setAccessible(true);
field.set(dialog, true);//设定为true,则可以关闭对话框/color]
禁止关闭:
[color=darkblue]field.setAccessible(true);
field.set(dialog, false); //设定为false,则不可以关闭对话框[/color]