美文网首页
如何让AlertDialog再点击了按钮后,DIalog不消失

如何让AlertDialog再点击了按钮后,DIalog不消失

作者: Ma_小鹏 | 来源:发表于2016-10-27 11:21 被阅读51次
在你的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();
}

亲测可用!

相关文章

网友评论

      本文标题:如何让AlertDialog再点击了按钮后,DIalog不消失

      本文链接:https://www.haomeiwen.com/subject/rbgjuttx.html