and what is the correct way to change
the background color on any View?
On any View
? What you have is correct, though you should drop the invalidate()
call.
However, some Views
already have backgrounds. A Button
, for example, already has a background: the face of the button itself. This background is a StateListDrawable
, which you can find in android-2.1/data/res/drawable/btn_default.xml
in your Android SDK installation. That, in turn, refers to a bunch of nine-patch bitmap images, available in multiple densities. You would need to clone and modify all of that to accomplish your green goals.
In short, you will be better served finding another UI pattern rather than attempting to change the background of a Button
.