Android Question Designer button and background image

dagnabitboy

Active Member
Licensed User
Longtime User
I've created a button with black background, rounded corners, and a white border in the designer. I want to add an image to the button to represent it's function. I've created the image, 3 white lines with a black background. Also tried an image with a transparent background. Loading the image removes the rounded corners and the white border. I've tried a few methods with bitmaps and bitmapdrawables but all result in the corners and border removed. Hopefully someone can point me in the right direction! Thanks in advance.

one method tried:
B4X:
Sub Globals
  Public bars3 As BitmapDrawable
End Sub

Activity_Create
  bars3.Initialize(LoadBitmap(File.DirAssets, "bars3.png" ))
  btnSettings.Background = bars3
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
Upvote 0

dagnabitboy

Active Member
Licensed User
Longtime User
I tried the example you referenced in the other thread by substituting button for panel, but I got the same result as before. Image loads fine, but the original characteristics of the button disappear. Studying this code led me to my own solution. I created a panel in the designer, same color, border color and width and radius as my buttons, so it looks identical. I was then able to add my image to the panel and create a click event for that image. So, thanks Cableguy for your suggestion!

Here's my code for anyone interested:

B4X:
Sub Process_Globals
   'These global variables will be declared once when the application starts.
   'These variables can be accessed from all modules.

End Sub

Sub Globals
   Dim button1 As Button
   Dim label1 As Label
   Dim panel1 As Panel
   Dim count As Int
   Dim bars3 As BitmapDrawable
   Dim iv As ImageView
End Sub

Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("test")     ' loads button1, panel1 and label1

   bars3.Initialize(LoadBitmap(File.DirAssets, "bars3.jpg"))
   label1.Text = "Count = 0""
   button1.Text = "Button"
   iv.Initialize("settings")    ' click event for image
   iv.Background = bars3
' the buttons and panel have a corner radius of 7, so I kept the view that far away from the panel edges.
   panel1.AddView(iv,7dip,7dip,panel1.Height*.8,panel1.Width*.8)   
   
End Sub

Sub Activity_Resume

End Sub

Sub Activity_Pause (UserClosed As Boolean)

End Sub

Sub button1_click
   count = count + 1
   label1.Text = "Count = " & count
End Sub

Sub settings_click
   count = count + 1
   label1.Text = "Count = " & count
End Sub
 

Attachments

  • Screenshot_20170915-184432.png
    39.6 KB · Views: 554
Upvote 0
Cookies are required to use this site. You must accept them to continue using the site. Learn more…