Android TextView textColor 错误解析:`?attr/tvMainColor` 属性使用问题
根据提供的 XML 布局文件,我没有看到明显的问题。但是根据错误信息中的 Caused by: java.lang.UnsupportedOperationException: Failed to resolve attribute at index 5: TypedValue{t=0x2/d=0x7f0304b7 a=-1},可能是由于在 TextView 的 textColor 属性中使用了无效的属性值。
请确保 ?attr/tvMainColor 是一个有效的属性值,并且在你的项目资源文件中定义了该属性。
如果你没有定义 tvMainColor 属性,或者该属性的值无效,可以尝试使用其他有效的颜色值,例如 #000000 表示黑色。
修改后的代码如下:
<TextView
android:id="@+id/tv_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Content"
android:textSize="20sp"
android:textColor="#000000"
android:singleLine="true"/>
<TextView
android:id="@+id/tv_time"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time"
android:textSize="20sp"
android:textColor="#000000"
android:singleLine="true"/>
请注意,如果你使用了自定义的属性 tvMainColor,请确保在项目的资源文件中正确定义了该属性,并且为其指定了有效的颜色值。
原文地址: https://www.cveoy.top/t/topic/bz0o 著作权归作者所有。请勿转载和采集!