I am trying to set a recyclerview item color based on a boolean in kotlin. But when the recylerview loads, it will not set its color with the code I have. Also, If I change the background that is tied to the recycler view item via xml programmatically, it will not change it to the new drawable, but will reset it back to its basic form. Please just at least let me know why my setBackgroundColor line is not setting the list item background to the color I designate.
@RequiresApi(Build.VERSION_CODES.O)
override fun onBindViewHolder(holder: AlarmViewHolder, position: Int) {
val alarm = alarmList[position]
holder.itemView.apply {
if (alarm.amPm) {
setBackgroundColor(context.getColor(R.color.todays_day_color))
}
Thanks all for the responses, I know it takes time to respond. Ty. I have marked the answer that solved it for me. I had to refer to the parent/child/whichever it is view layout and change its color and not the items color.
if (alarm.amPm) { list_item_layout_id.setBackgroundColor(context.getColor(R.color.todays_day_color)) } else list_item_layout_id.setBackgroundColor(context.getColor(R.color.black))