IconButton - Add a icon or an Picture to a button

DonManfred

Expert
Licensed User
Longtime User
Confirm
Will check and create this events
 

DonManfred

Expert
Licensed User
Longtime User
Update
V1.0.1
- Some new Events due to public request
- Some new Properties due to public request
Documentation and Library updated in #1


B4X:
Sub IconButton_Click
    Log("Button click")
End Sub
Sub IconButton_LongClick()
    Log("Button LongClick")
End Sub
Sub IconButton_Down()
    Log("Button down")
End Sub
Sub IconButton_Up()
    Log("Button up")
End Sub
Sub IconButton_HoverEnter()
    Log("Hover Enter")
End Sub
Sub IconButton_HoverExit()
    Log("Hover Exit")
End Sub
 

woniol

Active Member
Licensed User
Longtime User
thanks, new events work fine, but it seems that all of them have to be declared.
If i don't declare IconButton_Down i get:
B4X:
java.lang.Exception: Sub iconbutton_down was not found.
In standard button there is no need to declare all the event, just those that you need.

Could you please also add Color property?
 

DonManfred

Expert
Licensed User
Longtime User
just those that you need.
Can you please try v1.0.2 (updated in #1)
also add Color property?
The Textcolor you can set.
The Button has no color. I can not see any Property like this. I could create methods to change the backgrounddrawable
 

woniol

Active Member
Licensed User
Longtime User
Events work fine.
I think that's what B4A button color doest it sets the backgrounddrawable.
It would be nice to have it with your lib :)
 

woniol

Active Member
Licensed User
Longtime User
How to add thit button in code?
When I try like this:
B4X:
Dim pan As Panel
    pan.Initialize("")
    Dim btn As IconButton
    btn.Initialize("")
    pan.AddView(btn,0,0,100%x,50%y)
I get:
B4X:
error: incompatible types: IconButtonWrapper cannot be converted to View
_pan.AddView((android.view.View)(_btn),(int) (0),(int) (0),__c.PerXToCurrent((float) (100),ba),__c.PerYToCurrent((float) (50),ba));
 

Mousa Najafi

Member
Licensed User
Longtime User
Thanks Mr. DonManfred
This library is exactly what I was looking for my recent app.
Just I wish this beautiful library to have more features in setIcon sub. For example to set icon in center and text in
top left or right corner of button(for RTL languages)
 

leidex

Member
Licensed User
Longtime User
Hi Manfred,

i tried to change the button image after a click, a toggle picture ;)
like this
<code>
Sub ib3IconButton_Click
Log("Button 3")
Dim bm As BitmapDrawable
bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_achievement.png"))
ib3.setIcon(False,bm)
ib3.Initialize("ib3aIconButton")
End Sub
Sub ib3aIconButton_Click
Log("Button 3a")
Dim bm As BitmapDrawable
bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_android.png")))
ib3.setIcon(False,bm)
ib3.Initialize("ib3IconButton")
End Sub
</code>

after the first click the image chanced and the "achievement.png" is showed, after the second click the image not chanced.
do jou have a idea?

thank you
 

DonManfred

Expert
Licensed User
Longtime User
please use code tags! They does not starts with < and ends with > btw
Why are you initializing the button new?

B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Do not forget to load the layout file created with the visual designer. For example:
    Activity.LoadLayout("Layout1")
    Dim bm As BitmapDrawable
    bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_android.png"))
    ib1.Text = "Android"
    ib1.IconPadding = 50
    ib1.TextColor = Colors.Blue
    'ib1.setPadding
    ib1.setIcon(True,bm)

    Dim bm As BitmapDrawable
    bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_achievement.png"))
    ib2.Text = "Button"
    ib2.IconPadding = 50
    ib2.setIcon(False,bm)

    Dim bm As BitmapDrawable
    bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_barcode_2.png"))
    ib3.Text = ""
    ib3.IconPadding = 0
    ib3.setIcon(False,bm)
End Sub
[..]
Sub IconButton1_Click()
   Dim bm As BitmapDrawable
   bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_android.png"))
   ib3.setIcon(True,bm)
End Sub
Sub IconButton2_Click()
   Dim bm As BitmapDrawable
   bm.Initialize(LoadBitmap(File.DirAssets,"ic_action_achievement.png"))
   ib3.setIcon(True,bm)
End Sub
 

leidex

Member
Licensed User
Longtime User
Thank you for your fast answer!
I tried your code but on my asus memopad the image doesnt change!?

I intilaized the button again to call another click methode for the same button. this would be a toggle image button :) and after this the image changed once?

Thanks
 

leidex

Member
Licensed User
Longtime User
Ok, i understand. It works!!:cool:

I solved the toggle with an booelan.

Thank you for your patience ;)
 

Mousa Najafi

Member
Licensed User
Longtime User
Hi Manfred
For bigger buttons I need bigger textsize and setting an icon in the center and text in the top. both options does not implemented in library yet. I hope it would be possible to implement them easily
 

DonManfred

Expert
Licensed User
Longtime User
I hope it would be possible to implement them easily
i dont think so. I dont think that i can implement this at all.
This lib EXTENDS the native Android Buttonobject. But in behind it is still a button with all it´s rules to place the text.
Maybe the lib can be extended with much more knowledge about the buttonobject but i dont know how
 

woniol

Active Member
Licensed User
Longtime User
Could you please add Enabled property and a method to set Background ?
 
Top