B4A Library [Class] ActionBar

Informatix

Expert
Licensed 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

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

Last edited:

Informatix

Expert
Licensed User
Pretty interesting, how can I change text size of buttons etc.?
YourActionBar.SetText

B4X:
'Sets text of the given button
'You can set TextColor and TextSize to -1 to left them unchanged
Public Sub SetText(ID As View, Text As String, TextColor As Int, TextSize As Int)
 
Last edited:

bluedude

Well-Known Member
Licensed User
Mmm,

If I have this like in your sample AB2.AddButton(LoadBitmap(File.DirAssets, "home.png"), "HOME", 7, 1, "", "Home_LongClick")

How can I set the Textsize then? AB2.SetText and then? What is the ID of the View and how can I exactly know the ID of the view?
 

Informatix

Expert
Licensed User
Mmm,

If I have this like in your sample AB2.AddButton(LoadBitmap(File.DirAssets, "home.png"), "HOME", 7, 1, "", "Home_LongClick")

How can I set the Textsize then? AB2.SetText and then? What is the ID of the View and how can I exactly know the ID of the view?
The AddButton function returns the button ID (as explained in the function help). But, in the demo, I don't need to do something with the returned value most of the time so I don't store it. If you get it, you can use it to modify the button. The demo includes an example of use:
B4X:
         Dim Btn As View
         Btn = AB.AddButton(LoadBitmap(File.DirAssets, "home.png"), "", 2, 1, "", "Home_LongClick")
         AB.SetText(Btn, "Home", Colors.Yellow, -1)
 

Informatix

Expert
Licensed User
If someone wants to include nice graphics in the action bar (not detected as buttons, of course), this is very easy:
YourActionBar.AsPanel.AddView(YourImageView, ....

That works with all kind of views, except labels (reserved for the title) and panels (reserved for the buttons).
 

Informatix

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

With SetIconAsWideAsText, it's now possible to have tabs like the ones in the Android article on Action bars.

Starting tomorrow, I will publish tutorials to show how to use my classes and my libraries to replicate the UI of some applications made by professionals. That will show you some advanced techniques. For copyright reasons, that will be only text and screenshots. ;-)
 

Mahares

Well Known Member
Licensed User
@Fred: Although your CLASSES are very classy, I am getting confused, because you mentioned in one you posts that you have combined the FLoatingWindows and Actionbars or as you referred to a (split). But I still see 2 separate classes. Could you please clarify the confusion or set me in the right track?
Merci
 

Informatix

Expert
Licensed User
@Fred: Although your CLASSES are very classy, I am getting confused, because you mentioned in one you posts that you have combined the FLoatingWindows and Actionbars or as you referred to a (split). But I still see 2 separate classes. Could you please clarify the confusion or set me in the right track?
Merci
These two classes were only one at the beginning. Now, they live their own lives. I never said I have combined them.
 

Informatix

Expert
Licensed User
New version

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
 

mrossen

Active Member
Licensed User
Very Nice,

I have a simple question.

Have you made any functions for the overflow menu? The right menu with the 3 dots.

I would like to have 2 icons and the overflow icon on the bar. And under the overflow menu 5 other menu points. Is this possible.

Mogens
 
Last edited:
Top