错误可绘制对象和颜色不会在 textInputLayout 中更改

Error drawable and color don't change in textInputLayout

所以我使用的是 textInputLayout,我需要做的就是为错误图标设置自定义可绘制对象。这是我的布局和依赖项

    implementation 'com.google.android.material:material:1.2.0-beta01'
    <com.google.android.material.textfield.TextInputLayout
        style="@style/Widget.MaterialComponents.TextInputLayout.OutlinedBox"
        android:layout_width="match_parent"
        android:layout_height="@dimen/text_field_height"
        android:layout_margin="@dimen/activity_margin"
        android:hint="@string/insert_name_hint"
        app:boxBackgroundColor="@color/transparent"
        app:boxCornerRadiusBottomEnd="@dimen/text_field_corner"
        app:boxCornerRadiusBottomStart="@dimen/text_field_corner"
        app:boxCornerRadiusTopEnd="@dimen/text_field_corner"
        app:boxCornerRadiusTopStart="@dimen/text_field_corner"
        app:errorEnabled="true"
        app:errorTextColor="?colorAccent"
        app:errorIconDrawable="@drawable/ic_alert_black_24dp"
        app:errorIconTint="?colorAccent"
        app:errorContentDescription="@string/insert_name_hint"
        app:boxStrokeErrorColor="@color/gray"
        app:startIconDrawable="@drawable/ic_cool_black_24dp"
        app:startIconTint="@color/gray"
        app:hintAnimationEnabled="true"
        app:hintTextColor="?colorAccent">

        <com.google.android.material.textfield.TextInputEditText
            android:id="@+id/nameEvent"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:imeOptions="actionDone"
            android:maxLength="30"
            android:padding="0dp"
            android:textAlignment="center"
            android:textCursorDrawable="@null"
            android:inputType="textCapSentences"/>

    </com.google.android.material.textfield.TextInputLayout>

基本上,drawable 和 tints 不起作用,使用默认图标和颜色。其余的工作正常。我没有以编程方式设置任何内容。

好吧,这个问题有点简单,但我过了一会儿才发现。 这不是布局级别的问题,而是错误管理问题。必须在 Input Layout 而不是 Input EditText 上设置错误。所以这就是区别(当然我还必须向输入布局添加一个 id):

之前

customView.nameEvent.error = getString(R.string.invalid_value_name)

之后

customView.nameEventLayout.error = getString(R.string.invalid_value_name)

是的,简单。但我认为这可能是一个常见错误,所以我希望这个答案可以帮助那里的人。