【问题标题】:Cannot find the setter for attribute 'android:textColorHint' with parameter type int找不到参数类型为 int 的属性“android:textColorHint”的设置器
【发布时间】:2019-01-23 18:26:02
【问题描述】:

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

<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 引用,它会起作用。

【问题讨论】:

  • 将“app:textColorHint”改为“android:textColorHint”

标签: android


【解决方案1】:

不确定您是否还需要这个答案。但是该 attr 不起作用,因为它没有在 TextInputLayout.class 中提供设置器。因为那是一个 sdk 类 - 你不能改变它。问题出在构造函数内部,同时解析TintTypedArray

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

您可以尝试使用 TextInputLayout.setHintTextAppearance() 它在绑定中起作用。

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

现在看起来错误文本颜色提示文本颜色在错误状态下总是相同的(如果你调用TextInputLayout.setError()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-08-29
    • 2017-03-04
    • 2013-05-31
    • 1970-01-01
    • 2019-06-07
    • 1970-01-01
    相关资源
    最近更新 更多