android – 如何使TextInputLayout中的错误消息出现在中心

前端之家收集整理的这篇文章主要介绍了android – 如何使TextInputLayout中的错误消息出现在中心前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
目前它看起来像附加此布局:
<android.support.design.widget.TextInputLayout
    android:id="@+id/layoutCurrentPW"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    app:errorEnabled="true">

如何设置错误信息“密码必须至少为8个字符”到中心引力?
我尝试使用android:gravity =“center”,但这不起作用.

编辑
包含EditText的布局:

<android.support.design.widget.TextInputLayout
    android:id="@+id/layoutCurrentPW"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    app:errorEnabled="true">

        <EditText
            android:id="@+id/editTextCurrentPassword"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:layout_marginLeft="50dp"
            android:layout_marginRight="50dp"
            android:gravity="center"
            android:hint="@string/current_password"
            android:inputType="textPassword"
            android:textAppearance="?android:attr/textAppearanceMedium"
            android:textColor="@color/black" />
    </android.support.design.widget.TextInputLayout>

解决方法

我想知道是否有任何方法可以从框架中处理它…似乎没有.

但TextInputLayout的工作方式是:
– 当用户触摸时,提示显示在EditText的顶部.
错误消息将显示在TextInputLayout下面并对齐以启动.

由于提示错误消息之间的不对齐,我的EditText有40dp的left_margin.所以现在,我从EditText中删除了left_margin 40dp并将其应用于TextInputLayout本身,所以它现在看起来很好.

获得的经验:-)是否必须将任何边距应用于EditText,如果可能的话,更好的相同,可以应用于TextInputLayout以保持正确放置提示错误消息.

原文链接:https://www.f2er.com/android/309790.html

猜你在找的Android相关文章