`
z303729470
  • 浏览: 128917 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

Android alertdialog的按钮点击后不消失

 
阅读更多
使用反射:
  在你的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();
  }
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics