点击AlertDialog按钮不关闭对话框

//保持dialog不关闭的方法 private void keepDialogOpen(AlertDialog dialog) {
    try {
        java.lang.reflect.Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
        field.setAccessible(true);
        field.set(dialog, false);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

//关闭dialog的方法 private void closeDialog(AlertDialog dialog) {
    try {
        java.lang.reflect.Field field = dialog.getClass().getSuperclass().getDeclaredField("mShowing");
        field.setAccessible(true);
        field.set(dialog, true);
    } catch (Exception e) {
        e.printStackTrace();
    }
    dialog.dismiss();
}

你可能感兴趣的:(android,alert,dialog,不关闭)