当我写这段代码时,我想要setError
,但是当显示错误信息时,为TextInputLayout
设置红色背景TextInputLayout
!
I do not want set background!我希望只显示错误信息。
My code:
if (TextUtils.isEmpty(userName)) {
register_UserName_layout.setError("Insert Username");
}
XML代码:
<android.support.design.widget.TextInputLayout
android:id="@+id/register_userUsernameTextLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/register_headerLayout"
android:layout_margin="10dp"
android:textColorHint="#c5c5c5">
<EditText
android:id="@+id/register_userUserNameText"
android:layout_width="match_parent"
android:layout_height="40dp"
android:background="@drawable/selector_bg_edit"
android:hint="نام کاربری"
android:paddingBottom="2dp"
android:textColor="@color/colorAccent"
android:textCursorDrawable="@drawable/bg_input_cursor"
android:textSize="16sp" />
</android.support.design.widget.TextInputLayout>
我该如何解决这个问题呢?感谢所有<3
发布于 2016-08-28 14:35:17
if (TextUtils.isEmpty(userName)) {
register_UserName_layout.setError("Insert Username");
txtInpit.setColorFilter(R.color.white);
}
发布于 2016-12-13 04:21:24
我已经找到了解决此问题的方法。您只需要创建一个自定义的EditText并覆盖它的getBackground()方法来返回一个新的drawable。这样,TextInputLayout就不能在EditText的背景上设置滤色器,因为你不会返回EditText的背景,而是另一个可绘制的。如下所示:
@Override
public Drawable getBackground() {
return ContextCompat.getDrawable(getContext(), R.drawable.some_drawable);
}
并在TextInputLayout中使用自定义EditText:
<android.support.design.widget.TextInputLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<CustomEditText
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@drawable/custom_edit_text_bg" />
</android.support.design.widget.TextInputLayout>
发布于 2018-04-23 22:04:55
在我的例子中,我添加了一行
<shape android:shape="rectangle"
xmlns:android="http://schemas.android.com/apk/res/android" >
<stroke android:color="@color/lightGray" android:width="1dp"/>
<solid android:color="@color/transparent"/>
<padding android:top="7dp" android:bottom="7dp" android:left="7dp" android:right="7dp"/>
<corners android:radius="2dp"/>
</shape>
这只会产生红色边框,而不是整个背景
https://stackoverflow.com/questions/39188609
复制相似问题