Android Question Adding border to a BitmapDrawable button

jaraiza

Active Member
Licensed User
Longtime User
Hi,

I've been trying adding a border to a BitmapDrawable button with the known code

B4X:
Dim cd As ColorDrawable
cd.Initialize2(Colors.White, 5dip, 2dip, Colors.Black)
MyButton.Background  = cd

But setting the button to ColorDrawable makes the image to disappear, being replaced with the specified background color/transparency.

Is there any way to add the border without losing the image? (The images have been set as BitmapDrawable in the designer)

1759115618599.png


Thanks!
 

PaulMeuris

Well-Known Member
Licensed User
1759123394671.png
1759123457961.png

You can put the button on a panel and set the color of that panel to a color you like to have as the bordercolor.
Make the button in the designer a few dips smaller on each side.
1759123619531.png

This setting will display as the left image.
The right image uses an image with a transparant background and the color of the panel comes through it.
B4X:
'    Button1.SetBackgroundImage(LoadBitmap(File.DirAssets,"angelfish.jpg"))
    Button1.SetBackgroundImage(LoadBitmap(File.DirAssets,"angelfish_transparant.png"))
 
Upvote 0
Top