setPositiveButton中添加:
//用于不关闭对话框
try { Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field.setAccessible(true); field.set(dialog, false); } catch (Exception e) { e.printStackTrace(); }
添加上述代码后就可以使dialog无法关闭,在你需要关闭的地方,添加:
//关闭对话框
try { Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field.setAccessible(true); field.set(dialog, true); } catch (Exception e) { e.printStackTrace(); }