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:

Adilson Jacinto

Active Member
Licensed User
Longtime User
You have a demo, you have the source code of the class, you have the solution. And you want me to write your code? You're kidding?

No, I don't want you to write the code I just wanted to point me out in the write direction.
I have done what you asked me to do but it does not work.
I created 4 global variables for this.
B4X:
    Dim btn_home As View
    Dim btn_qlist As View
    Dim btn_appinfo As View
    Dim btn_settings As View

Then in activity create I have the following

B4X:
btn_home = AB.AddButton(LoadBitmap(File.DirAssets, "home.png"), "", 2, 1, "Home_Click", "")
    AB.SetText(btn_home, "Home", Colors.Yellow, -1)
    btn_qlist = AB.AddButton(LoadBitmap(File.DirAssets, "listQ.png"), "Q-List", 2, 2, "QueueList_Click", "")
    btn_appinfo = AB.AddButton(LoadBitmap(File.DirAssets, "info.png"), "App Info", 2, 3, "Info_Click", "")
    btn_settings = AB.AddButton(LoadBitmap(File.DirAssets, "rsettings.png"), "Settings", 2, 4, "Settings_Click", "")

Then in the button clcick
B4X:
Sub Home_Click(ActionBar As ClsActionBar, Btn As View)
  
    ' We remove everything from the action bar before displaying a new style

    AB.SetText(btn_home, "Home", Colors.Yellow, -1)
    AB.SetText(btn_qlist, "Q-List", Colors.White, -1)
    AB.SetText(btn_settings, "Settings", Colors.White, -1)

  
End Sub

And I do the above for the other buttons and it does not work @Informatix !!!


@Informatix I think it does not like colors.white because I tried different collors and it worked. So what is the default color for white?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
No, I don't want you to write the code I just wanted to point me out in the write direction.
I have done what you asked me to do but it does not work.
I created 4 global variables for this.
B4X:
    Dim btn_home As View
    Dim btn_qlist As View
    Dim btn_appinfo As View
    Dim btn_settings As View

Then in activity create I have the following

B4X:
btn_home = AB.AddButton(LoadBitmap(File.DirAssets, "home.png"), "", 2, 1, "Home_Click", "")
    AB.SetText(btn_home, "Home", Colors.Yellow, -1)
    btn_qlist = AB.AddButton(LoadBitmap(File.DirAssets, "listQ.png"), "Q-List", 2, 2, "QueueList_Click", "")
    btn_appinfo = AB.AddButton(LoadBitmap(File.DirAssets, "info.png"), "App Info", 2, 3, "Info_Click", "")
    btn_settings = AB.AddButton(LoadBitmap(File.DirAssets, "rsettings.png"), "Settings", 2, 4, "Settings_Click", "")

Then in the button clcick
B4X:
Sub Home_Click(ActionBar As ClsActionBar, Btn As View)
 
    ' We remove everything from the action bar before displaying a new style

    AB.SetText(btn_home, "Home", Colors.Yellow, -1)
    AB.SetText(btn_qlist, "Q-List", Colors.White, -1)
    AB.SetText(btn_settings, "Settings", Colors.White, -1)

 
End Sub

And I do the above for the other buttons and it does not work @Informatix !!!


@Informatix I think it does not like colors.white because I tried different collors and it worked. So what is the default color for white?
Your code should work.

If I do these changes to the demo:
- I add "Dim BtnFavorite As View" to Globals
- I add "BtnFavorite=" before "AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Favorite", 5, 2, "Tab_Click", "Star_LongClick")"
- I add "AB.SetText(BtnFavorite, "Favorite", Colors.Blue, -1)" in Tab_Click(...)
Then the Favorite word becomes blue when I click on any tab (with the Tab style).
 

Adilson Jacinto

Active Member
Licensed User
Longtime User
Your code should work.

If I do these changes to the demo:
- I add "Dim BtnFavorite As View" to Globals
- I add "BtnFavorite=" before "AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Favorite", 5, 2, "Tab_Click", "Star_LongClick")"
- I add "AB.SetText(BtnFavorite, "Favorite", Colors.Blue, -1)" in Tab_Click(...)
Then the Favorite word becomes blue when I click on any tab (with the Tab style).


As I edited my previous post, it works with any color apart from colors.white, I cannot put it back to the default color
 

Informatix

Expert
Licensed User
Longtime User
As I edited my previous post, it works with any color apart from colors.white, I cannot put it back to the default color
Because Colors.White = -1. I didn't notice it when I did the class. If you set the color to Colors.RGB(254,254,254), the result will be visually white but the value of the color will be different from -1.
 

Adilson Jacinto

Active Member
Licensed User
Longtime User
Because Colors.White = -1. I didn't notice it when I did the class. If you set the color to Colors.RGB(254,254,254), the result will be visually white but the value of the color will be different from -1.

Thanks Colors.RGB(254,254,254) worked fine :)
 

ma7tin

Member
Licensed User
Hi, how to make working 3 dot menu on the right side of ClsActionBar like a other menus from other packages ? Please help ..
 
Top