目前它看起来像附在这个布局上:
<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.
更多推荐
发布评论