如何在 TextInputLayout 中使用 conter min length

How can be able to use conter min length in TextInputLayout

我有一个 EditText 包裹在 TextInputLayout 中。 TextInputLayout 有一个最大长度选项。示例如下:

app:counterMaxLength="12"

是否可以为 counterMinLength 设置一个选项?例如,如果我输入的密码长度不能小于一定长度。

我不认为它有这样的属性,因为当 activity 创建时它有一个空字符串值,这打破了 "min length" 约束。

因此,为了解决这个问题,我认为您应该验证 java/kotlin 代码中的长度,例如:

if(editText.getText().toString().length() > MIN_VALUE) {
   // do somthing
}

我认为他们目前不支持此选项:)

但我认为如果您愿意,可以轻松创建自定义 Edittext,然后使用

验证输入字段的最小数量
edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {
        @Override
        public void onFocusChange(View v, boolean hasFocus) {
            if (!hasFocus) {
                if (edt.getText().toString().trim().length() < 8) {
                    edt.setError("Minimum length exception");
                }
            } 

或者你可以 addTextChangedListener 为你的 edittext

类似的东西。 ^^