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,784
Last edited:

incendio

Well-Known Member
Licensed User
Longtime User
Has anyone got an error when using action bar class under Lollipop 5.0.0?

I got an error :
java.lang.IllegalArgumentException: unknown bitmap configuration

The error raised when call to functions
B4X:
AB.SameWidthForAll(True)
AB.AddButton(Null, "System", 5, 1, "SysClick", "")

But change the codes to this
B4X:
AB.SameWidthForAll(False)
AB.AddButton(Null, "System", 5, 1, "SysClick", "")

No error raised. Tested it under an Genymotion Emulator. Don't have a change to test it on real device cause don't have device with Lollipop.
 

Informatix

Expert
Licensed User
Longtime User
Has anyone got an error when using action bar class under Lollipop 5.0.0?

I got an error :
java.lang.IllegalArgumentException: unknown bitmap configuration

The error raised when call to functions
B4X:
AB.SameWidthForAll(True)
AB.AddButton(Null, "System", 5, 1, "SysClick", "")

But change the codes to this
B4X:
AB.SameWidthForAll(False)
AB.AddButton(Null, "System", 5, 1, "SysClick", "")

No error raised. Tested it under an Genymotion Emulator. Don't have a change to test it on real device cause don't have device with Lollipop.

Tested with 5.1 on a Nexus 7: no error.
Do you use the latest version?
 

Traiser

Member
Licensed User
Longtime User
hi, if i set the height panel at 50 the icon dimension is 50 , how to reduce only dimension icon? Thanks
 

kepler

Active Member
Licensed User
Longtime User
Hi,

Great work.

Just one question: is there a way to change the tab color? I've tryed:

B4X:
pnlAB.Color = Colors.ARGB(255,204,204,204)

but it didn't work...

Kind regards,

Kepler
 

cimperia

Active Member
Licensed User
Longtime User
Do you mean, the "line", orange or gray, at the base of the tab? If it is what you mean then the class uses png files to set them.
 

cimperia

Active Member
Licensed User
Longtime User
Hi,

Great work.

Just one question: is there a way to change the tab color? I've tryed:

B4X:
pnlAB.Color = Colors.ARGB(255,204,204,204)

but it didn't work...

Kind regards,

Kepler

I misread your question. You can change the panel color this way:
B4X:
  pnlAB.AsPanel.Color = Colors.ARGB(255,204,204,204)
 

kepler

Active Member
Licensed User
Longtime User
Hi Informatix :)

I've got a question. The Action Bar doesn't work if we compile the B4A app in the obfuscated mode code release.

Any ideas how to handle this problem?

Kind regards,

Kepler
 

kepler

Active Member
Licensed User
Longtime User
Hi,

Not quite... I've remembered the rules for obfuscating. I was calling one of the menus like this:

B4X:
AB.AddButton(LoadBitmap(File.DirAssets, "home.png"), "", 4, 1, "Home", "")

The action parameter "Home" is turned into a string - so it's not assumed as the defined action. If we, however, put "Home_m" (notice the "_", no blank spaces) as the action, the string is not modified, and everything goes right :)

Kind regards,

Kepler
 

Informatix

Expert
Licensed User
Longtime User
The action parameter "Home" is turned into a string - so it's not assumed as the defined action.

??? I don't understand what you mean.
This parameter is the event name (the complete name of the sub handling the event) so you have to name it like an event name, e.g. Home_Click. Look at the demo. If you name it only "Home", it is not properly named and it won't work with obfuscation.
 

kepler

Active Member
Licensed User
Longtime User
Hi,

Yes, I've realized that. But it's not necessary to put, for instance, the "_Click" text.
I was using it - wrongly - calling a routine like this:

B4X:
Sub Home (ActionBar As ClsActionBar, Btn As View)

And it worked with no obfuscation.

Now, I'm calling:

B4X:
Sub Home_m (ActionBar As ClsActionBar, Btn As View)

And it works aswell - obfuscated or not.

Either way, the action must not have any white spaces, otherwise it won't work if the code is obfuscated - that's my assumption.

Kind regards,

Kepler
 

Peter Simpson

Expert
Licensed User
Longtime User
I've come across underscore (_) issues previously too, but with WebViewExtra. I was going to mention adding an underscore as explained by @wonder in another post, I also believe that @Erel has explained about this too. I was not 100% sure if adding an underscore would work for you though, so I never posted a response @kepler.
 
Last edited:

Adilson Jacinto

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

View attachment 13455 View attachment 13456 View attachment 13519 View attachment 13520
View attachment 13613

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

How do I change the color text of the other buttons when not active?
I know AB.SetText(Btn, "Q-List", Colors.Yellow, -1 ) will set the color for that button but what about make the others white?

Thanks
 
Top