如何使TextInputLayout中的错误消息出现在中心(How to make error message in TextInputLayout appear in center)

编程入门 行业动态 更新时间:2024-10-24 12:20:34
如何使TextInputLayout中的错误消息出现在中心(How to make error message in TextInputLayout appear in center)

目前它看起来像附在这个布局上:

<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>

Currently it looks as in attached with this layout:

<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">

How to set the error message "password must at least be 8 characters" to center gravity ? I tried with android:gravity="center" but that did not work.

EDIT Layout that includes 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下方并对齐开始。

由于提示和错误消息之间的错位,我有40dp的left_margin给我的EditText。 所以现在,我从EditText中删除了left_margin 40dp,并将其应用于TextInputLayout本身,因此现在看起来很好。

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

I wanted to know if there is any way to handle it from framework..seems no.

But the way TextInputLayout work is: - hint will be shown on top of EditText when user touches it. - Error messages will be shown just under the TextInputLayout and aligned to start.

I had 40dp of left_margin to my EditText due to which misalignment between hint and error message. So for now, I removed left_margin 40dp from EditText and applied same to TextInputLayout itself so it looks fine now.

Lesson learnt :-) is if any margins has to be applied to EditText, better same, if possible, can be applied to TextInputLayout to keep hint and error messages to be placed properly.

更多推荐

本文发布于:2023-07-31 02:33:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1340556.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:出现在   错误   消息   中心   TextInputLayout

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!