android 带有自定义背景的 textInputEditText 无法正常工作

android textInputEditText with custom background is not working ok

我在 textInputLayout 中使用 textInputEditText 我必须为我的 editText 设置背景才能为我的 editText 实现带边框的视图。 但是当我在 textInputLayout 上调用 setError() 时,整个 editText 颜色变为红色。 但我只想更改错误文本的颜色,而不是整个视图。

之前设置错误:

screen shot

设置错误后:

screen shot

这是我的 xml 代码:

<android.support.design.widget.TextInputLayout
            android:layout_alignParentTop="true"
            android:id="@+id/ex_pass_holder"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:passwordToggleEnabled="false"
            android:gravity="right">
            <android.support.design.widget.TextInputEditText
                android:id="@+id/ex_pass_et"
                android:layout_width="fill_parent"
                android:layout_height="50dp"
                android:hint="رمز عبور فعلی"
                android:inputType="textPassword"
                android:textColor="#000"
                android:textSize="15sp"
                android:gravity="right|center"
                android:background="@drawable/edittext_bg"
                android:padding="8dp"
                />
        </android.support.design.widget.TextInputLayout>

请帮帮我,我做错了什么?

我通过扩展 TextInputLayout 和覆盖一些方法解决了这个问题

public class CustomTextInputLayout extends TextInputLayout {

    public CustomTextInputLayout(Context context, AttributeSet attrs) {
        super(context, attrs);
    }



    @Override
    public void setError(@Nullable CharSequence error) {
        super.setError(error);
        try {
            EditText et = getEditText();
            Drawable editTextBackground = et.getBackground();
            editTextBackground.clearColorFilter();

        }catch (Exception e){
            e.printStackTrace();
        }
    }

    @Override
    protected void drawableStateChanged() {
        super.drawableStateChanged();
        try {
            EditText et = getEditText();
            Drawable editTextBackground = et.getBackground();
            editTextBackground.clearColorFilter();

        }catch (Exception e){
            e.printStackTrace();
        }
    }
}