B4A Library [Lib] Compact ActionBar

This library will create a Compact ActionBar.

You can display a clickable Logo, a Menu button and up to 20 action buttons, the ActionBar can also auto-hide.

Requirements:

- B4A 6.x+
- Add the following files to your assets directory:
  • ActionBarLogo.png
  • ActionBarMenuButton.png
  • ActionBarPullTab.png
Note: You can use your own png's, but you MUST keep the same names.

How to install:

- Copy the CustomCompactActionBar.jar and CustomCompactActionBar.xml to your additional libraries directory.

How to use:

B4X:
'Initialize the library
Dim ActionBar As CustomCompactActionBar

'Create the ActionBar
ActionBar.Initialize(Activity, Me, "Manager", "", "", Colors.ARGB(255, 20, 20, 20), Colors.ARGB(255, 160, 160, 160), True, True, True)

'Add some ActionButtons
'NOTE: The action buttons SUPPORTS ONLY GRAPHICS.
ActionBar.AddBarIcon(mIcon1.Bitmap, 1)
ActionBar.AddBarIcon(mIcon1.Bitmap, 2)
ActionBar.AddBarIcon(mIcon1.Bitmap, 3)
ActionBar.AddBarIcon(mIcon1.Bitmap, 4)

'If you want to add a menu
ActionBar.SetMenu(200dip, 200dip, Null, "", Colors.DarkGray, Typeface.DEFAULT)

'Add menu items
For I = 1 To 10

    ActionBar.AddMenuItem(LoadBitmap(File.DirAssets, "ActionBarLogo.png"), "Item " & I, Colors.White, I)

Next

The click events are captured by doing the following:
B4X:
Sub Manager_Click(ViewClicked As String, Value As Object)

    'You can use SELECT CASE or IF...THEN to process the return, the possible results are:
    'Logo, 0           = The logo was clicked
    'BarIcon, <value>  = A bar icon was clicked
    'MenuItem, <value> = A menu item was clicked

    ToastMessageShow("Result = " & ViewClicked & CRLF & "Value = " & Value, False)

End Sub

NOTE: This new version breaks previous versions, check the NEW library name (it is called now CustomCompactActionBar) and there are also additional parameters. Please check the attached sample for details.

Screenshots:
3d1SDUHl.png
-
ZtVlR4rl.png
 

Attachments

  • CustomCompactActionBar_Sample.zip
    19.5 KB · Views: 526
  • CustomCompactActionBar_Lib_1.8.zip
    9.8 KB · Views: 604
Last edited:

Wolfgang Trageiser

Member
Licensed User
Longtime User
the library is very good.

the .BringToFront works fine for the bar itself, but still the drop-down menu does not come to the foreground with the bar.
so the toolbar is not to use whitout the drop-down-menu coming in foreground.
do you have a solution?
 

LucianoB

Member
Licensed User
Longtime User
Hello.
First of all thanks for this great job!!
Anyway I'm having a small problem loading a background image to the action bar.
I have this code:
B4X:
Sub Activity_Create(FirstTime As Boolean)

  'The images can be taken from resources or load your own
   
  mIcon1 = p.GetResourceDrawable(17301583)
  mIcon2 = p.GetResourceDrawable(17301586)
  mIcon3 = p.GetResourceDrawable(17301582)
  mIcon4 = p.GetResourceDrawable(17301577)
   
  Dim bb As Bitmap
  bb.Initialize(File.DirAssets,"actionbarbackground.jpg")
  ActionBar.Initialize(Activity, Me, "Manager", bb, Colors.ARGB(255, 20, 20, 20), Colors.ARGB(255, 160, 160, 160), True, True, True)
  ' THE ABOVE LINE GIVES ME AN ERROR LOADING THE BITMAP

  ActionBar.AddBarIcon(mIcon1.Bitmap, 1)
  ActionBar.AddBarIcon(mIcon2.Bitmap, 2)
  ActionBar.AddBarIcon(mIcon3.Bitmap, 3)
  ActionBar.AddBarIcon(mIcon4.Bitmap, 4)
   
  ActionBar.SetMenu(200dip, 200dip, Null, Colors.DarkGray)

  For I = 1 To 10

  ActionBar.AddMenuItem(LoadBitmap(File.DirAssets, "ActionBarLogo.png"), "Item " & I, Colors.White, I)

  Next

End Sub

The ActionBar.Initialize gives me an error:
java.io.FileNotFoundException: /storage/emulated/0/Android/data/njdude.compact.actionbar/files/virtual_assets/(bitmap): 679 x 198: open failed: ENOENT (No such file or directory)
even if the image is in the files folder and synced.
What am I doing wrong?
 
Top