Explorar o código

0.0.50.beta30.pre
- 修复 inputInfo 指定最大长度时可能导致 InputDialog 输入框无法选中、输入法无法弹出的问题,其本质原因为:在指定 MAX_LENGTH 时需要设置 inputType 包含 InputType.TYPE_CLASS_TEXT,否则设置无法生效,InputFilter.LengthFilter 必须配合 TYPE_CLASS_TEXT 使用,但强制设置 InputType.TYPE_CLASS_TEXT 又会导致设置 inputType 为 InputType.TYPE_CLASS_NUMBER 时可以输入除数字以外的小数点,这不符合预期,目前的修复方案为检查是否包含有效的类标志,如果没有设置有效的类标志,默认添加 TYPE_CLASS_TEXT 来避免出现问题,详见 MessageDialog.java:683~693 测试可以兼容两种情况以解决问题。

Kongzue hai 3 meses
pai
achega
f6e2fde0dc

+ 10 - 2
DialogX/src/main/java/com/kongzue/dialogx/dialogs/MessageDialog.java

@@ -680,9 +680,17 @@ public class MessageDialog extends BaseDialog {
             }
 
             if (inputInfo != null) {
-                if (inputInfo.getMAX_LENGTH() != -1)
-                    txtInput.setFilters(new InputFilter[]{new InputFilter.LengthFilter(inputInfo.getMAX_LENGTH())});
                 int inputType = inputInfo.getInputType();
+                if (inputInfo.getMAX_LENGTH() != -1) {
+                    int inputClass = inputType & InputType.TYPE_MASK_CLASS;
+                    if (inputClass != InputType.TYPE_CLASS_TEXT &&
+                            inputClass != InputType.TYPE_CLASS_NUMBER &&
+                            inputClass != InputType.TYPE_CLASS_PHONE &&
+                            inputClass != InputType.TYPE_CLASS_DATETIME) {
+                        inputType = (inputType & ~InputType.TYPE_MASK_CLASS) | InputType.TYPE_CLASS_TEXT;
+                    }
+                    txtInput.setFilters(new InputFilter[]{new InputFilter.LengthFilter(inputInfo.getMAX_LENGTH())});
+                }
                 if (inputInfo.isMultipleLines()) {
                     inputType = inputType | InputType.TYPE_TEXT_FLAG_MULTI_LINE;
                 }