Can you help me with my code? I am changing the color of the item based on the information from the database, and now I wanted to transfer the color to the CardView, but I don't know what the notation should look like, because this code tells me that the Color.RED write is wrong. Will you help me?
@Override
protected void onBindViewHolder(@NonNull holder holder, int position, @NonNull
VoiceModel model) {
holder.tvvoiceName.setText(model.getName());
holder.tvvoiceTime.setText(model.getTime());
if(model.getPremium() == 1) holder.voice_item.getCardBackgroundColor(Color.RED);
CodePudding user response:
You have to use setCardBackgroundColor
not getCardBackgroundColor
. Then your code should be:
holder.voice_item.setCardBackgroundColor(Color.RED);
CodePudding user response:
You can try this code:
holder.voice_item.setCardBackgroundColor(ContextCompat.getColor(this, R.color.here_put_your_color));