在密码类型的EditText上使用setError方法时出现双感叹号的问题

6
在我的应用程序中,我使用设计支持库的TextInputLayout来包装所有需要提示标签效果的EditText。然而,我注意到这样做有一个不利影响-将其应用于密码字段会使setError方法应用两个感叹号:一个位于EditText的中间,另一个位于正确位置,稍微遮盖了“眼睛”(密码可见性)图标。

enter image description here

这只会发生在输入类型设置为textPassword的字段上。

我该如何解决这个问题?

编辑:

XML布局

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
     <EditText
        android:id="@+id/loginEmail"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_email"
        android:inputType="textEmailAddress"/>            
</android.support.design.widget.TextInputLayout>

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">
    <EditText
        android:id="@+id/loginPassword"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:hint="@string/hint_password"
        android:inputType="textPassword"/>
</android.support.design.widget.TextInputLayout>

请发布XML代码。 - Sangram Haladkar
添加了布局代码! - fonix232
http://code.tutsplus.com/tutorials/creating-a-login-screen-using-textinputlayout--cms-24168 - Sangram Haladkar
1个回答

9
尝试仅针对TextInputLayout设置错误消息,并从editText对象中删除它。

但这会改变错误显示的性质。我们不能使用TextInputLayout的setError方法在末尾添加一个浮动标签吗? - Kalyan Dechiraju
这会改变错误的样式。我想要同时看到眼睛和错误,而不是错误图标覆盖在眼睛上面。所以,我认为这不是正确的答案。目前,我没有找到任何解决办法,只能添加自己的 ImageView… - Cocorico
@Cocorico,你找到解决方案了吗?我也在尝试实现同样的事情,但是还没有找到任何方法。 - Blablablabli

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接