-4

I want to change the background color of cardview whenever user clicks on it. Can anyone suggest me a way to do that?

prog94
  • 11
  • 5
  • 2
    obviously somethink like `onClick() { cardView.setColor(newColor); }` (of course it's just a pseudo code) **what had you tried so far?** – Selvin May 22 '17 at 09:29
  • @jayeshsolanki93 he is asiking about the colour change with the user click. But your link is not pointing out that bro – Manojkanth May 22 '17 at 09:34
  • @Selvin I have tried to do it inside onClick but setColor is giving me error – prog94 May 22 '17 at 09:37
  • Thanx @Selvin for your suggestion I tried it using setCardBackgroundColor and its working – prog94 May 22 '17 at 09:53

1 Answers1

0

use setCardBackgroundColor() like this in onClick() method:

    cardView1.setCardBackgroundColor(R.color.colorPrimary);
Ashish Gupta
  • 737
  • 11
  • 18