B4A Library [Class] ActionBar

Hi,

This class allows to create Action Bars.

There was already a good library to do that (AHActionBar) but I needed more features and more flexibility. So here is my version.

Tutorials: How they do #2, How they do #3

Classic.png Menu.png Tab.png Ribbon.png
DragAndDrop.png

v1.1:
Fixed a bug in RemoveButton
Added ReplacePressedDrawable
Fixed a bug in the demo

v1.2:
New functions:
- ReplaceDividerDrawable(Drawable As Object)
- SetIconAsWideAsText(Enabled As Boolean)
Updated the demos

v1.3:
Fixed a bug in ResizeButton (the text height was not correctly computed)
New function: FillParent
Removed the limitation of SetFixedWidth (there's no longer minimum width)

v1.4:
Optimized the loading of drawables
Added the Drag&Drop feature
New functions:
- getLeftPosition(Btn As View) As Int
- getRightPosition(Btn As View) As Int
- StartDragAndDrop(Btn As View, ViewToBlock As Object, OnAfterDropSub As String)
- AbortDragAndDrop
- MoveButtonTo(Btn As View, NewPosition As Int)
Renamed ID to Btn in function parameters

v1.41:
Fixed an issue with JellyBean.
Fixed a visual bug with successive Drag&Drops.

v1.42:
Fixed the computation of the text size of buttons;
No more warnings with B4A v2.7.

v1.43:
Fixed a bug (division by zero).

Enjoy,
Fred
 

Attachments

  • ActionBar v1.43.zip
    62.8 KB · Views: 1,907
Last edited:

Douglas Farias

Expert
Licensed User
Longtime User
i m upgraded my android to 4.3.3 too and i m using this class no problem o_O
moto g
 

Informatix

Expert
Licensed User
Longtime User
i m upgraded my android to 4.3.3 too and i m using this class no problem o_O
moto g
I just read french articles on this new version and it seems there are a few issues introduced with it, so they recommend to not upgrade for now (e.g. this link in english). That explains maybe why I didn't receive any proposal of update from Google for my Nexus 7 (usually Nexus devices are the first to be upgraded).
 

inakigarm

Well-Known Member
Licensed User
Longtime User
Hi:

I'd try to use your great class but I've a problem when I've begin to test it; Taking your demo on ActionBar (v1.43), with B4A 3.82 and Reflection lib (2.4), when I change the code of an actionbar button from Long_Click to Click, the behavior seems the same as with LongClick (need a long time click to show the toastMessage)

Is this normal actionbar behavior ??

PD: only change this
B4X:
actbar1.AddButton(LoadBitmap(File.DirAssets, "refresh.png"), "", 5, -1, "", "Refresh_Click")

Sub Refresh_Click(ActionBar As ClsActionBar, Btn As View)
    ToastMessageShow("Refresh", False)
End Sub
 

Informatix

Expert
Licensed User
Longtime User
Hi:

I'd try to use your great class but I've a problem when I've begin to test it; Taking your demo on ActionBar (v1.43), with B4A 3.82 and Reflection lib (2.4), when I change the code of an actionbar button from Long_Click to Click, the behavior seems the same as with LongClick (need a long time click to show the toastMessage)

Is this normal actionbar behavior ??

PD: only change this
B4X:
actbar1.AddButton(LoadBitmap(File.DirAssets, "refresh.png"), "", 5, -1, "", "Refresh_Click")

Sub Refresh_Click(ActionBar As ClsActionBar, Btn As View)
    ToastMessageShow("Refresh", False)
End Sub
You just changed the name of the event. Nothing more. If you want to receive a different event, move the last parameter in AddButton or add a parameter for Click events.
 

shasunder

Member
Licensed User
Longtime User
Hi

Let us assume that i have 3 buttons in Actionbar. How to click the button programatically. I know it can be achieved by using Reflection. Could some one shed light to me please...

lasttab = AB.AddButton(LoadBitmap(File.DirAssets, "tab_selected.png"), "Home", 5, 1, "Home_Click", "Home_LongClick")
AB.SetIconAsWideAsText(True)
AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Favorite", 5, 2, "Star_Click", "Star_LongClick")
AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Share", 5, 3, "Share_Click", "Share_LongClick")


Sub Home_Click(ActionBar As ClsActionBar, btn As View)
If lasttab.IsInitialized Then
AB.ReplaceIcon(lasttab, LoadBitmap(File.DirAssets, "tab_normal.png"))
End If
AB.ReplaceIcon(btn, LoadBitmap(File.DirAssets, "tab_selected.png"))
lasttab = btn

Sub Share_Click(ActionBar As ClsActionBar, btn As View)
If lasttab.IsInitialized Then
AB.ReplaceIcon(lasttab, LoadBitmap(File.DirAssets, "tab_normal.png"))
End If
AB.ReplaceIcon(btn, LoadBitmap(File.DirAssets, "tab_selected.png"))
lasttab = btn

Sub Refresh_Click(ActionBar As ClsActionBar, btn As View)
If lasttab.IsInitialized Then
AB.ReplaceIcon(lasttab, LoadBitmap(File.DirAssets, "tab_normal.png"))
End If
AB.ReplaceIcon(btn, LoadBitmap(File.DirAssets, "tab_selected.png"))
lasttab = btn
 

shasunder

Member
Licensed User
Longtime User
To click a button programatically, just call its Click sub (...or I don't understand the question).
Thanks Informatix.

If it is
Sub btn_new()

then calling btn_new will work. But for this case

Share_Click(ActionBar As ClsActionBar, btn As View)

if I call share_click I get the below error

B4A version 4.30
Parsing code. 0.06
Compiling code. Error
Error compiling program.
Error description: Syntax error (missing parameter).
Occurred on line: 143
Share_Click
Word: share_click
 

Informatix

Expert
Licensed User
Longtime User
Thanks Informatix.

If it is
Sub btn_new()

then calling btn_new will work. But for this case

Share_Click(ActionBar As ClsActionBar, btn As View)

if I call share_click I get the below error

B4A version 4.30
Parsing code. 0.06
Compiling code. Error
Error compiling program.
Error description: Syntax error (missing parameter).
Occurred on line: 143
Share_Click
Word: share_click
Your error is explicitely given: Syntax error (missing parameter).
You forgot to pass parameters to the function.
 

shasunder

Member
Licensed User
Longtime User
Your error is explicitely given: Syntax error (missing parameter).
You forgot to pass parameters to the function.
That is where I am having problem with. Dont know how to pass the parameters for action bar and button.My action bar is defined as "AB".
Some how I solved it by other work around. But Still interested to know how to programatically click.
 

Informatix

Expert
Licensed User
Longtime User
That is where I am having problem with. Dont know how to pass the parameters for action bar and button.My action bar is defined as "AB".
Some how I solved it by other work around. But Still interested to know how to programatically click.
??? The function has two parameters: ActionBar As ClsActionBar, btn As View. Then pass the action bar (AB) and the button. Where's the difficulty ?
 

shasunder

Member
Licensed User
Longtime User
??? The function has two parameters: ActionBar As ClsActionBar, btn As View. Then pass the action bar (AB) and the button. Where's the difficulty ?
Thanks informatix. Your thought helped me. This is how it worked.

homebtn = AB.AddButton(LoadBitmap(File.DirAssets, "tab_selected.png"), "Home", 5, 1, "Home_Click", "Home_LongClick")
AB.SetIconAsWideAsText(True)
If FirstTime=True Then lasttab =homebtn
favbtn= AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Favorite", 5, 2, "Star_Click", "Star_LongClick")
sharebtn =AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Share", 5, 3, "Share_Click", "Share_LongClick")
refbtn =AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "About", 5, 4, "Refresh_Click", "Refresh_LongClick")

and calling

Star_Click(AB,favbtn)

worked. Thanks. Thanks again.
 

BarryW

Active Member
Licensed User
Longtime User
I love this...

Is there any animated transition when button is remove or icon is replaced? Just an idea. Tnx...
 
Top