目前,它看起来与此布局相同:
<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" 但这不起作用。
![enter image description here](https://i.stack.imgur.com/YYI4i.png)
EDIT
包含 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 的工作方式是:
- hint将显示在 EditText 之上当用户触摸它时。
- 错误信息将仅显示在 TextInputLayout 下并对齐开始。
由于提示和错误消息之间未对齐,我的 EditText 的 left_margin 为 40dp。所以现在,我从 EditText 中删除了 left_margin 40dp 并将其应用到 TextInputLayout 本身,所以现在看起来很好。
吸取的教训:-) 是,如果必须将任何边距应用于 EditText,最好将其应用于 TextInputLayout,以保持提示和错误消息正确放置。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)