【问题标题】:Android Material design error validation does not appearAndroid Material design 错误验证不出现
【发布时间】:2021-04-15 13:14:19
【问题描述】:

当我在编辑文本中添加错误消息时。

我看到了图标,但是点击图标后默认不会出现错误提示

这是我的布局文本

<com.google.android.material.textfield.TextInputLayout

                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_centerVertical="true"
                android:hint="@string/enter_client_name">


                <com.google.android.material.textfield.TextInputEditText
                    app:errorEnabled="true"
                    android:id="@+id/editTextClientName"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
            </com.google.android.material.textfield.TextInputLayout>

这是java代码:

if(t.getClientName().equals("")){
            editTextClientName.setError( "Client name is required!" );
            return false;
        }

【问题讨论】:

    标签: android material-design material-components-android


    【解决方案1】:

    你只是犯了一个简单的错误,给你的 TextInputLayout 一个 id 然后调用 setError 方法而不是 TextInputEditText。

    这样做:

    <com.google.android.material.textfield.TextInputLayout
    
                android:id="@+id/textInputLayout"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:layout_centerVertical="true"
                android:hint="@string/enter_client_name">
    
    
                <com.google.android.material.textfield.TextInputEditText
                    android:id="@+id/editTextClientName"
                    app:errorEnabled="true"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"/>
            </com.google.android.material.textfield.TextInputLayout>
    

    Java 代码:

    if(t.getClientName().equals("")){
            textInputLayout.setError( "Client name is required!" );
            return false;
        }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-09-27
      • 2016-09-25
      • 1970-01-01
      • 2020-09-30
      • 1970-01-01
      • 2017-12-19
      • 1970-01-01
      • 2016-03-13
      相关资源
      最近更新 更多