Skip to content
Advertisement

Android Button color changes to another color

I am creating a simple quiz app. And want to change the color of button to green if answer is correct, and to red if answer is incorrect.If i change color through xml of layout it is normally changed, but when I write

JavaScript

color changes but totally to another color (dark blue). Why colors are not changed as supposed?

themes.xml:

JavaScript

XML:

JavaScript

Java:

JavaScript

Advertisement

Answer

It happens because the method setBackgroundColor(@ColorInt int color) works with a @ColorInt, not a resource (@ColorRes)

Use:

JavaScript

or something like:

JavaScript
User contributions licensed under: CC BY-SA
1 People found this is helpful
Advertisement