相关疑难解决方法(0)

出错时不要更改TextInputLayout后台

我想将一个带有背景的EditText作为"普通"EditText,但是对TextInputEditText进行错误处理(错误消息显示在底部,而不是"!"drawable出现).

我有这样的事情:

<android.support.design.widget.TextInputLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:setError="@{viewModel.error}">

    <android.support.design.widget.TextInputEditText

        android:layout_width="match_parent"
        android:layout_height="wrap_content"

        android:background="@drawable/simple_edit_text_background"
        android:ellipsize="end"
        android:inputType="textMultiLine|textNoSuggestions"
        android:text="@={viewModel.value}"

        style="@style/MyEditTextStyle" />

</android.support.design.widget.TextInputLayout>
Run Code Online (Sandbox Code Playgroud)

但似乎当我在TextInputLayout上设置错误时,它将背景drawable(在普通的TextInputEditText中,下划线)更改为错误TextView的颜色.

这就是我的EditText的样子: 在此输入图像描述

我们可以在以下方法中的TextInputLayout代码中看到它:

private void updateEditTextBackground() {
    if (mEditText == null) {
        return;
    }

    Drawable editTextBackground = mEditText.getBackground();
    if (editTextBackground == null) {
        return;
    }

    ensureBackgroundDrawableStateWorkaround();

    if (android.support.v7.widget.DrawableUtils.canSafelyMutateDrawable(editTextBackground)) {
        editTextBackground = editTextBackground.mutate();
    }

    if (mErrorShown && mErrorView != null) {
        // Set a color filter of the error color
        editTextBackground.setColorFilter(
                AppCompatDrawableManager.getPorterDuffColorFilter(
                        mErrorView.getCurrentTextColor(), PorterDuff.Mode.SRC_IN));
    } else if (mCounterOverflowed && mCounterView != null) {
        // Set …
Run Code Online (Sandbox Code Playgroud)

android android-textinputlayout

13
推荐指数
2
解决办法
7641
查看次数

标签 统计

android ×1

android-textinputlayout ×1