Java - getCardBackgroundColor - color for CardView

Viewed 29

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);
2 Answers

You have to use setCardBackgroundColor not getCardBackgroundColor. Then your code should be:

holder.voice_item.setCardBackgroundColor(Color.RED);

You can try this code:

holder.voice_item.setCardBackgroundColor(ContextCompat.getColor(this, R.color.here_put_your_color));
Related