IconButton - Add a icon or an Picture to a button

DonManfred

Expert
Licensed User
Longtime User

MaFu

Well-Known Member
Licensed User
Longtime User
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

Shouldn't be a problem.
The standard button have a Gravity property for horizontal/vertical text aligning. The icon button miss this property and ignores the settings from designer.
If you add "Gravity" and additionally a property "IconGravity" with the same behaviour for the icon all text/icon position combinations are doable.
 

zeuspower

Member
Licensed User
Longtime User
Great lib !
In your example when I click the button it "clicks" ok (it changes color for a few msecs so the user knows it'clicked..)
But in my App does not ,whats the problem ?
 

woniol

Active Member
Licensed User
Longtime User
Great lib !
In your example when I click the button it "clicks" ok (it changes color for a few msecs so the user knows it'clicked..)
But in my App does not ,whats the problem ?

Do you change background color?
 

zeuspower

Member
Licensed User
Longtime User
!
Yap,that was the problem ! Thanks
But how can i choose a background color and not lose the "click" functionality ?
 

woniol

Active Member
Licensed User
Longtime User
Last edited:

Rusty

Well-Known Member
Licensed User
Longtime User
Nice library, can you add a visible attribute? i.e. ib1.visible = true / ib1.visible = false
Also, I would like to be able to overlay the graphic in SOME cases but use the offset in most cases. If I set the offset to zero, this doesn't seem to overlay, but move the text right up to the graphic. Can we use a negative offset to make this happen?
Thanks,
Rusty

I got the negative offset to work :), please disregard that part of my questions. Still need the visible method.
 

peacemaker

Expert
Licensed User
Longtime User
1) Is Icon size not scaled for the button height ? Seems, not :-(
2) Try to get "but.Height" gives error
B4X:
** Activity (main) Create, isFirst = true **
Error occurred on line: 52 (Main)
java.lang.NullPointerException
    at de.donmanfred.IconButtonWrapper.getHeight(IconButtonWrapper.java:273)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:636)
    at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:302)
    at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:238)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:121)
    at b4a.example.main.afterFirstLayout(main.java:100)
    at b4a.example.main.access$100(main.java:17)
    at b4a.example.main$WaitForLayout.run(main.java:78)
    at android.os.Handler.handleCallback(Handler.java:733)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:136)
    at android.app.ActivityThread.main(ActivityThread.java:5021)
    at java.lang.reflect.Method.invokeNative(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:515)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:827)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:643)
    at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **

Button added via Designer.
 
Last edited:

peacemaker

Expert
Licensed User
Longtime User
Just your sample with added
B4X:
Log(ib3.Height)
 

ykucuk

Well-Known Member
Licensed User
Longtime User
There is 3 button and 1 click event.

i added ib1_Click event but it doesnt fired when click on this
i tried with sender also but it gave error
any help
 

rleiman

Well-Known Member
Licensed User
Longtime User
Shouldn't be a problem.
The standard button have a Gravity property for horizontal/vertical text aligning. The icon button miss this property and ignores the settings from designer.
If you add "Gravity" and additionally a property "IconGravity" with the same behaviour for the icon all text/icon position combinations are doable.

Please do add "IconGravity" so I can get my images to scale with the button size.

Thanks.
 
Top