Android Alert Dialog点击按钮对话框不关闭
2016-10-12 15:02
337 查看
今天项目中有用到Alert Dialog,然后是设置密码进入界面,设置密码界面有两个dialog,在第一个dialog需要判断密码是否正确,然后在进行下一步,但是每次在点击确定按钮或者取消按钮,dialog都会直接关闭,如果你写dismiss,或者return等等都是没有用的,所以今天我们只需要添加几句代码就可以实现关闭或不关闭的功能啦。
不关闭dialog:
关闭dialog:
具体代码用法:
field.set(dialog, false);//这句代码这只成false表示不关闭dialog;true表示关闭dialog
具体的还可以参考下面的这篇文章哦,分享给大家!
http://longshuai2007.blog.163.com/blog/static/14209441420111130104435932/
不关闭dialog:
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.Builder ab=new AlertDialog.Builder(this); ab.setTitle("Title"); ab.setView(edit); ab.setPositiveButton("确定", new OnClickListener() { @Override public void onClick(DialogInterface dialog, int arg1) { if (edit.getText().toString().length()==0) { ***try { Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing"); field.setAccessible(true); field.set(dialog, **false**); } catch (Exception e) { e.printStackTrace(); }*** } } }).show();
field.set(dialog, false);//这句代码这只成false表示不关闭dialog;true表示关闭dialog
具体的还可以参考下面的这篇文章哦,分享给大家!
http://longshuai2007.blog.163.com/blog/static/14209441420111130104435932/
相关文章推荐
- Android Alert Dialog解决点击按钮对话框不关闭/的问题
- Android Alert Dialog解决点击按钮对话框不关闭的问题
- Android实现点击AlertDialog上按钮时不关闭对话框的方法
- Android:实现点击AlertDialog上按钮时不关闭对话框
- Android实现点击AlertDialog上按钮时不关闭对话框的方法
- Android——点击对话框上按钮不关闭对话框
- Android中AlertDialog 点击按钮后不关闭对话框的功能
- Android——点击对话框上按钮不关闭对话框
- 【Android】AlertDialog点击按钮后不自动关闭对话框
- Android——点击对话框上按钮不关闭对话框
- Android实现点击AlertDialog上按钮时不关闭对话框的方法
- Android设置AlertDialog点击按钮对话框不关闭(转)
- Android Alert Dialog解决点击按钮对话框不关闭/的问题
- Android:实现点击AlertDialog上按钮时不关闭对话框
- Android——点击对话框上按钮不关闭对话框
- Android Alert Dialog解决点击按钮对话框不关闭的问题
- Android Dialog点击按钮不关闭对话框
- Android Alert Dialog解决点击按钮对话框不关闭/的问题
- Android——点击对话框上按钮不关闭对话框
- Android——点击对话框上按钮不关闭对话框