简体   繁体   中英

TextColor is changing to wrong one

I'm just trying to change textcolor in my recyclerview using this code ↓↓↓

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 . You should use Resources to convert the R.color to color the resource represents

Try below code-

ContextCompat.getColor(context, R.color.green)

ContextCompat.getColor(context, R.color.red)

setTextColor期望可以由R.color提供的Color的“ int” 。“ 颜色代码而不是resId。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM