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:

tman

Member
Licensed User
Longtime User
NJDude,
Great library! Just what I needed - an Action Bar that doesn't use up valuable screen space. One question. If I load my layout first then initialize the ActionBar everything works good. If I choose a menu item to load a different layout the new layout seems to load on top of the ActionBar. (covering it up) Do I have to reinitialize it again after loading a new layout? Thanks again for another good library.
 

NJDude

Expert
Licensed User
Longtime User
NJDude,
Great library! Just what I needed - an Action Bar that doesn't use up valuable screen space. One question. If I load my layout first then initialize the ActionBar everything works good. If I choose a menu item to load a different layout the new layout seems to load on top of the ActionBar. (covering it up) Do I have to reinitialize it again after loading a new layout? Thanks again for another good library.
I have modified the library and added "BringToFront" you can call that after loading a layout.
 

elbelli2013

Member
Licensed User
Longtime User
Hi NJDude

I try compact bar in Jelly Belly and in Lollipop,
In Jelly Belly the compactBar work fine, but en Lollipop don't work right, because the bar stay behind of buttons of my aplication.

I try with ActionBar.BringToFront but this sentence does nothing

Do you have any idea of what is happening ?

regards
 

NJDude

Expert
Licensed User
Longtime User
Looking quickly at you code I see a problem, you are overlapping the actionBar, for example "LV1" is all the way to the top, you need at least 50dip which is the ActionBar height, you can get that like this:
B4X:
BarHeight = ActionBar.CompactActionBarHeight
 

Jeffrey Cameron

Well-Known Member
Licensed User
Longtime User
@NJDude: I've finally had a chance to look at this, and very nicely done! Once thing I did notice, while the .BringToFront works fine for the bar itself, the drop-down menu does not come to the foreground with the bar.

And one suggestion: I could not get a swipe down to work on the bar tab when in auto-hide, I could only get it to drop down/up if I clicked on the tab. It would be nice if you could add a gesture capture for swipe on the tab.
 

NJDude

Expert
Licensed User
Longtime User
@NJDude: I've finally had a chance to look at this, and very nicely done! Once thing I did notice, while the .BringToFront works fine for the bar itself, the drop-down menu does not come to the foreground with the bar.

And one suggestion: I could not get a swipe down to work on the bar tab when in auto-hide, I could only get it to drop down/up if I clicked on the tab. It would be nice if you could add a gesture capture for swipe on the tab.
Ok, I will take a look when I get a chance. Regarding the Swipe, it might be a little problematic since the tab is sort of small, but I will see if I can add that to the lib.

Thanks
 

sasetcolombia

Member
Licensed User
Longtime User
I need to load a new layout, when an icon bar is pressed,but this error is generated:
Error has ocurred in Sub:java.lang.NullPointerException

This is my code in Manager_Click...
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)
Select Case Value
Case 1
Activity.RemoveAllViews
Activity.LoadLayout("main2")
Case 2
Activity.RemoveAllViews
Activity.LoadLayout("main")
Case 3
End Select
End Sub


What is the error?

Download project here:
https://mega.co.nz/#!hYARhajZ
https://mega.co.nz/#!hYARhajZ


Thank you for your help!
 

Attachments

  • Screenshot_2015-05-16-19-33-51.png
    Screenshot_2015-05-16-19-33-51.png
    39 KB · Views: 226

jaraiza

Active Member
Licensed User
Longtime User
Hi! This a nice addition, NJDude :) Does this library work in Android 2.x? I've many clients reluctant to upgrade so I can't use ActionBars :mad:

Thanks!
 
Top