Reputation: 7947
I would have thought that there would be a variety of options in connection with a button's background from an image, for example the image could be tiled, or stretched or centred etc etc, but when I list a button's methods I can't see anything. Now I'm suspecting that it could be a two stage process, perhaps getting some kind of view first and then using a method of that view. Or maybe there is simply no control whatsoever concerning a button background. Please advise.
Upvotes: 0
Views: 43
Reputation: 22232
Note that any View
's background is something that fills the area covered by that View
, so you can't have it centered.
Stretching the the default behaviour, that's why a state list of 9-patches the the best thing to use for Button
's background.
If you want tiled background, you may use XML Bitmap with tileMode="repeat"
. See also other kinds of Drawable
s on this site. You can for example make something that feels like centered background image using Inset Drawable
.
And finally the functions are there: setBackgroundDrawable
and setBackgroundResource
.
Upvotes: 2