您的位置:首页 > 其它

Dialog设置为点击空白处/点击按钮后 不消失

2017-03-02 17:42 369 查看
private void showNoticeDialog() {
UtilsTools.Log_e(TAG, "-----showNoticeDialog");
try {
AlertDialog.Builder mDialog = new AlertDialog.Builder(mContext);
mDialog.setTitle(" 发现新版本啦! \n 请前往更新享受更好的体验。").setPositiveButton("前往更新", new DialogInterface.OnClickListener() {

public void onClick(DialogInterface dialog, int which) {
UtilsTools.Log_e(TAG, "to update --- url --- " + updateUrl);
Field field = null;
try { // 这一块是点击按钮后不消失
field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, false);
} catch (Exception e) {
e.printStackTrace();
}
}
});
// 点击空白处是否消失 1-不消失 0-不消失
if (is_forced_update.equals("1")) {
mDialog.setCancelable(false);
} else {
mDialog.setCancelable(true);
}
mDialog.create().show();
} catch (Exception e) {

}
}

设置点击按钮不可消失后,如果要改为点击按钮消失,改为:

field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
field.setAccessible(true);
field.set(dialog, true);
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: