-1

This is my first time asking a question here, so apologies if I do something wrong.

I have been using this playlist to make a RecyclerView in my app, with individual CardViews. I want to make it so that when a cardview is clicked, it will change the card to a slightly dark gray, to indicate that it was clicked. However, I don't know how to go about doing this. If someone could help me, that would be greatly appreciated! Let me know if you need any more info.

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
DangItsPang
  • 29
  • 1
  • 2

2 Answers2

0

On onclick() method you just have to change card background color. You can do this by this command.

card.setCardBackgroundColor(color);
Zeeshan Ali
  • 667
  • 8
  • 16
0

On the setOnClickListener method, you have to add

card.setCardBackgroundColor(colorYouWant);

and you can add it directly to the onBindViewHolder in the adapter class of the RecycleView.

Hope it works for you!

Ronak Sethi
  • 607
  • 5
  • 12
  • Thanks for this! I had created a sample cardview that would be used for the recylerview, but the cardview itself didn't have an id, so I couldn't access it. Hopefully this comment might help others who had this as well. – DangItsPang Jun 08 '20 at 18:32