找不到属性的设置者' android:textColorHint'参数类型为int

时间:2018-02-09 02:56:19

标签: android

我正在尝试使用数据绑定在textColorHint视图上设置<android.support.design.widget.TextInputLayout>,如

<android.support.design.widget.TextInputLayout
            android:layout_width="match_parent"
            android:layout_height="@dimen/text_input_layout_height"
            android:layout_marginBottom="@dimen/text_input_margin_bottom"
            android:hint="@{FieldHandlers.hasValidSpaces(account.firstName)? @string/first_name : @string/invalid_firstname}"
            app:textColorHint="@{FieldHandlers.hasValidSpaces(account.firstName)? @android:color/holo_red_light : @android:color/holo_red_light}"/>

然而它会给出以下错误消息:

Error:(70, 38) Cannot find the setter for attribute 'app:textColorHint' with parameter type int on android.support.design.widget.TextInputLayout. 

有没有办法可以使用此属性进行数据绑定?如果我直接传入颜色文字或@color/myColor引用,它就可以工作。

1 个答案:

答案 0 :(得分:0)

不确定是否仍然需要此答案。但是,该attr不起作用,因为它没有TextInputLayout.class中提供的setter。而且那就是sdk类-您不允许更改它。问题在于解析器TintTypedArray的构造函数内部:

if (a.hasValue(R.styleable.TextInputLayout_android_textColorHint)) {
        mDefaultTextColor = mFocusedTextColor =
                a.getColorStateList(R.styleable.TextInputLayout_android_textColorHint);
    }

您可以尝试使用TextInputLayout.setHintTextAppearance()在绑定内有效。

警告:但请注意,支持库版本28中引入了一些行为更改。

看起来像错误文本颜色提示文本颜色现在在错误状态下始终相同(如果您要调用TextInputLayout.setError()