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

查看:67
本文介绍了如何使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">

如何将错误消息密码必须至少为8个字符"设置为中心重心?
我尝试了android:gravity ="center",但是没有用.

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.

编辑
包含EditText的布局:

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>

推荐答案

我想知道是否有任何方法可以从Framework ..似乎没有.

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

但是TextInputLayout的工作方式是:
-提示会在用户触摸时显示在 EditText顶部上.
-错误消息将显示在 TextInputLayout 下,并对齐以开始.

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.

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

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.

经验教训:-)是,如果必须对EditText应用任何边距,则最好在可能的情况下,对TextInputLayout应用相同的边距,以保持提示和错误消息的正确放置.

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.

这篇关于如何使TextInputLayout中的错误消息出现在中心的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆