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:

mrossen

Active Member
Licensed User
Longtime User
Thank for your help.

I will use the SlidingSidebar class. It looks perfect for me.

Mogens
 

barx

Well-Known Member
Licensed User
Longtime User
Just starting to try this. Can set up a bar and buttons no worries. How do you add a title?

Also, can other views be added? I wish to add a textview and use it for search. Maybe I'm thinking along the wrong lines of the use of this. Looks nice so far though.

cheers
 

barx

Well-Known Member
Licensed User
Longtime User
Just a note for future users.

The .AddButton Does NOT return a button, it returns a panel ;)
 

Informatix

Expert
Licensed User
Longtime User
Just starting to try this. Can set up a bar and buttons no worries. How do you add a title?

Also, can other views be added? I wish to add a textview and use it for search. Maybe I'm thinking along the wrong lines of the use of this. Looks nice so far though.

MyActionBar.Title for the title (it's a label)

MyActionBar.AsPanel.AddView to add other views
 

barx

Well-Known Member
Licensed User
Longtime User
MyActionBar.Title for the title (it's a label)

MyActionBar.AsPanel.AddView to add other views

Nice.

How about calculating space.

Say I want a 'x' at right (set to position -1, 48dip wide) and then a 'Search' button (set to position -2, auto size) then I want the edit text to mount left side 5dip in and take up rest of space??

Thought something like

B4X:
btnActionSearch = ActionBar.AddButton(Null, "Search", 7, -2, "btnActionSearch_Click", "")

ActionBar.AsPanel.AddView(ActionBarSearchText, 5dip, 5dip, ActionBar.AsPanel.Width - btnActionSearch.Left, 40dip)

but no joy.

Any tips ;)
 

Informatix

Expert
Licensed User
Longtime User
B4X:
btnActionSearch = ActionBar.AddButton(Null, "Search", 7, -2, "btnActionSearch_Click", "")

ActionBar.AsPanel.AddView(ActionBarSearchText, 5dip, 5dip, ActionBar.AsPanel.Width - btnActionSearch.Left, 40dip)

The right formula is: ActionBar.AsPanel.AddView(ActionBarSearchText, 5dip, 5dip, btnActionSearch.Left - 10dip, 40dip)
 
Last edited:

barx

Well-Known Member
Licensed User
Longtime User
Nice one Info'

Works a treat.
 

barx

Well-Known Member
Licensed User
Longtime User
Loving this class so far. Got one little issue that I don't know if can be sorted in the class or whether I just need to consume the event.

Basically if I add a button but do not specify a _LongClick event name. Then run the app and for some reason end up long clicking. A NullPointerException is raised and app closes.

As I said, not sure if it a bug that requires fixing or if I should just put in a _LongClick name and leave the sub blank.

Thanks and keep up the great work.
 

Informatix

Expert
Licensed User
Longtime User
Loving this class so far. Got one little issue that I don't know if can be sorted in the class or whether I just need to consume the event.

Basically if I add a button but do not specify a _LongClick event name. Then run the app and for some reason end up long clicking. A NullPointerException is raised and app closes.

As I said, not sure if it a bug that requires fixing or if I should just put in a _LongClick name and leave the sub blank.

Thanks and keep up the great work.

Are you using the latest B4A version with the latest Reflection library?
If the OnLongClickSub parameter is left empty in AddButton, there's no reason to raise an exception since the listener is invalidated.
 

barx

Well-Known Member
Licensed User
Longtime User
B4A - 2.20

Reflection 1.90

I tried it with specifying a name for the longclick and simply not writing any sub to match, seems to solve it but guess it wastes resources by creating a un-used/needed listener.

What would you suggest?
 

barx

Well-Known Member
Licensed User
Longtime User
Cheers for the tip, just updating reflection. Didn't realize there was a later version.
 

barx

Well-Known Member
Licensed User
Longtime User
Sorted, thx
 

wheretheidivides

Active Member
Licensed User
Longtime User
Remember the B in BASIC stands for beginners.

I am a tard and I freely admit it. How do I install this add-on and then call the funtions? I have a menu and just want a simple conversion to a action bar

B4X:
'Menu
   Activity.AddMenuItem("Title Screen","Help") 'top left
   Activity.AddMenuItem("Instructions","Help") 'top center
   Activity.AddMenuItem("Return To Game","Help") 'top right
   
   Activity.AddMenuItem("Zero Stats","Help") 'bottom left
   Activity.AddMenuItem("Debug (On/Off)","Help") 'bottom center
   
   Activity.AddMenuItem("Continuation Bet (On/Off)","Help") 'more 1
   Activity.AddMenuItem("Double/Triple Down (On/Off)","Help") 'more 2
   Activity.AddMenuItem("Split 2 Card Pairs (On/Off)","Help") 'more 3
   Activity.AddMenuItem("Sound Effects (On/Off)","Help") 'more 4
 

Informatix

Expert
Licensed User
Longtime User
Remember the B in BASIC stands for beginners.

I have no obligation to do things for beginners.

I am a tard and I freely admit it. How do I install this add-on and then call the funtions?

It's a class, so copy the file "ClsActionBar.bas" into your project with Add Existing Module and declare it in Globals with Dim MyActionBar As ClsActionBar.

Did you study how the demo is made ?
 

wheretheidivides

Active Member
Licensed User
Longtime User
I have no obligation to do things for beginners.



It's a class, so copy the file "ClsActionBar.bas" into your project with Add Existing Module and declare it in Globals with Dim MyActionBar As ClsActionBar.

Did you study how the demo is made ?

I opened the demo up but it wouldn't run. Says refector isnt there or something. So to answer your and erel's questions, yes we do read stuff before asking questions. it's just the people writing stuff are writing for advanced users.
 

barx

Well-Known Member
Licensed User
Longtime User
That's because you are required to use the Reflection Lib.
 

Djembefola

Active Member
Licensed User
Longtime User
yes we do read stuff before asking questions.

After reading some of your posts, i have the impression that you read stuff but never try to understand stuff.
If programming is overstraining and frustrating you, why don't you consider finding another hobby? Cooking, Tap Dance, Synchronized Swimming...there are so many opportunities. ;)
 
Top