Android Question How to set background image for Buttons

ducphu

Active Member
Licensed User
Longtime User
Hi all,

Here is my questions, I have an array of buttons, e.g btn(50) as buttons.

1. How do I set image as background for all buttons in the array? Can I do it with animated image, and how?

2. How to adjust the size of the background image. Let say my button is a square a x a. I want to set the background image to 95%a, leaving a border which is filled with color. Something like:
wallpaper-and-borders-1-wallpaper-background-hd.png



whereby I have a blue border with my background image in center.

3. Continue from question 2, how can I make a blinking effect to the border ?

Thank you all for helping :)
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
The image you posted is broken.

1. Changing the button background is easier with the designer as the background is a StateListDrawable. You can however create a StateListDrawable by code or just set the background to a regular bitmap by creating a BitmapDrawable and setting it as the button background.
There is no such thing as an animated image. You will need to animate it yourself with a timer.

2. See this tutorial: Nine patch images tutorial
 
Upvote 0
Top