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)



Thanks!
 

PaulMeuris

Well-Known Member
Licensed User

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.

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
Cookies are required to use this site. You must accept them to continue using the site. Learn more…