setBackgroundColor(). (Android Studio) Can't understand how to use it to change the color of the background

156 Views Asked by At

I need the background to turn green when the button is clicked, many tutorials say to use: backgroundView.setBackgroundColor(Color.GREEN) but it doesn't work. The code:

It shows an error: Type mismatch: inferred type is Color but Int was expected Can't understand what to do and why doesn't it work in my case. Thank you

Activity_main.xml looks like this:

1

There are 1 best solutions below

0
Kartik Agarwal On
backgroundView.setBackgroundColor(Color.GREEN)

Points to remember:

The Color class should import android.graphics.Color and color GREEN should be in caps or you can use custom color from your colors.xml file using getColor() method