[英]TextColor is changing to wrong one
I'm just trying to change textcolor in my recyclerview using this code ↓↓↓ 我只是想使用此代码在recyclerview中更改textcolor↓↓↓
itemView.resultTV.textColor = if (result >= 0) R.color.green else R.color.red
But it changes the color to light purple, which is neither basic color nor green nor red. 但是它将颜色更改为浅紫色,既不是基本颜色,也不是绿色或红色。
Any ideas? 有任何想法吗?
you are using the resId
of the color, while setTextColor
expects the Color
. 您正在使用颜色的
resId
,而setTextColor
需要Color
。 You should use Resources to convert the R.color to color the resource represents
您应该使用资源将R.color转换为资源
represents
颜色
Try below code- 试试下面的代码-
ContextCompat.getColor(context, R.color.green)
ContextCompat.getColor(context, R.color.red)
setTextColor期望可以由R.color提供的Color的“ int” 。“ 颜色代码 ”而不是resId。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.