B4A Library IconButton - Add a icon or an Picture to a button

Discussion in 'Additional libraries, classes and official updates' started by DonManfred, Feb 17, 2015.

  1. DonManfred

    DonManfred Expert Licensed User

    IconButton
    Version:
    1.11
    • IconButton
      Events:
      • Click()
      • Down()
      • HoverEnter()
      • HoverExit()
      • LongClick()
      • Up()
      Methods:
      • AddToParent (Parent As ViewGroup, left As Int, top As Int, width As Int, height As Int)
        programmatically add the view (the Button)
      • DesignerCreateView (base As PanelWrapper, lw As LabelWrapper, props As Map)
      • Initialize (EventName As String)
      • setIcon (LeftSide As Boolean, d As Drawable)
      • setPadding (left As Int, top As Int, right As Int, bottom As Int)
        Sets the Padding for this Button
      Properties:
      • Background As Drawable [write only]
        Sets the Buttons background
      • BackgroundColor As Int [write only]
        Sets the Buttons background color
      • BackgroundDrawable As Drawable [write only]
        Sets the Buttons background drawable (deprecated)
      • Enabled As Boolean [write only]
        Sets the Buttons enabled state
      • Height As Int
      • IconPadding As Int [write only]
        Set the Padding between Text and Icon
      • Left As Int
      • Text As String [write only]
        Set the Text
      • TextAlignment As Void
        Sets the Alignment for this Button
      • TextColor As Int [write only]
        Sets the Textcolor for this Button
      • Top As Int
      • Typeface As Typeface
        Sets the Typeface for this Button
      • Width As Int


    Code:
    Dim bm As BitmapDrawable
        bm.Initialize(
    LoadBitmap(File.DirAssets,"ic_action_alarm.png"))
        ib1.Text = 
    "Button"
        ib1.IconPadding = 
    50
        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_android.png"))
        ib3.Text = 
    "Button"
        ib3.IconPadding = 
    50
        ib3.setIcon(
    False,bm)
    [​IMG]
     

    Attached Files:

    Last edited: Dec 19, 2015
  2. Tom Christman

    Tom Christman Active Member Licensed User

    The icons seem to be missing from the file folder.
     
  3. DonManfred

    DonManfred Expert Licensed User

    Sorry. HEre they are
     

    Attached Files:

  4. bluedude

    bluedude Well-Known Member Licensed User

    Hi donManfred, you are exactly doing the nice stuff that we need :-0
     
    DonManfred likes this.
  5. NJDude

    NJDude Expert Licensed User

    Nice, but better re-pack the sample including the icons.
     
  6. thedesolatesoul

    thedesolatesoul Expert Licensed User

    So picky
     
    Peter Simpson and NJDude like this.
  7. DonManfred

    DonManfred Expert Licensed User

    i have replaced the example-zip (including icons)
     
    Peter Simpson likes this.
  8. RandomCoder

    RandomCoder Well-Known Member Licensed User

    I've not had chance to play with any of your latest libraries yet but just wanted to post here to show my appreciation for the hard work you have obviously put in to creating these excellent additions to B4A for us.

    Thank you.
     
    DonManfred likes this.
  9. DonManfred

    DonManfred Expert Licensed User

    due to a problem with my libraries or why?
     
  10. RandomCoder

    RandomCoder Well-Known Member Licensed User

    Time my friend, there's never enough time! I can't believe we're almost in March, where did January and February go? :confused:
     
  11. DonManfred

    DonManfred Expert Licensed User

    hehe, fully aggree

    Are you in a timemachine or what let you think it´s already march? :D

    Edit: I needed to google "Almost"... Ok, no timemachine ;)

    Time is running away fast if you are not boring. Aggree ;-)
     
    RandomCoder likes this.
  12. Mahares

    Mahares Well Known Member Licensed User

    @DonManfred: This is a very nice library. You have become a powerhouse in just a short period of time since you joined the forum.
    Can you please add a few more properties like: TextColor, etc. I tried to change the text color in the designer but it does not have any effect.
     
  13. leidex

    leidex Member Licensed User

    Hi Manfred,
    nice work!
    How do i check which button is clicked?

    Thank you
     
  14. DonManfred

    DonManfred Expert Licensed User

    You can add the button in designer and set the correct eventname. Then you just need to manually create the clickevent.
    Asuming you set "IB" as the eventname then you need a sub like
    Code:
    Sub IB_Click
        
    Log("Button clicked")
    End Sub
    You can create this eventsub with

    sub+[space]+[tab]+iconbutton

    too.

    Sadly the event can not be set in designer... I dont know why. Or better said; i dont know whether i can do something to let the designer create this event with the contectual popup to create members.
     
    Last edited: Feb 18, 2015
  15. DonManfred

    DonManfred Expert Licensed User

    I´m here since 2 Years now... I started learning java (to be able to write new libraries (because i LOVE B4A and i want new Features to it...)) three months ago

    What exactly? I dont want to blow up the lib with dozend of methods which will not be used and just make the lib bigger
    But i can add more methods though
     
    Last edited: Feb 18, 2015
    Peter Simpson likes this.
  16. Peter Simpson

    Peter Simpson Expert Licensed User

    Ooh this is really good stuff @DonManfred.
    You surely are on a roll...
     
    DonManfred likes this.
  17. leidex

    leidex Member Licensed User

    thank you!
     
  18. DonManfred

    DonManfred Expert Licensed User

    Instead of an "Icon" you can load an real Image... See what the button will look like using this 200px x 355px Image
    charly.jpg


    [​IMG]
     
    Peter Simpson likes this.
  19. woniol

    woniol Active Member Licensed User

    Would it be possible to add events:

    Down
    Up
    LongClick

    to make compatible with standard B4A button?
     
  20. DonManfred

    DonManfred Expert Licensed User

    Down and up you dont have with normal buttons or not....

    Will have a look
     
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice