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

jmon

Well-Known Member
Licensed User
Longtime User
Thanks,

Actually both of my requests are answered by adding more transparent space around the icon. :)
Don't know how I didn't think about that!

Sent from my GT-P7500 using Tapatalk HD
 

Inman

Well-Known Member
Licensed User
Longtime User
I am trying to make the Actionbar title text scroll automatically so that it show longer text. On a label, this is done this way:

B4X:
Dim r As Reflector
 r.Target = TextView
 r.RunMethod2("setLines", 1, "java.lang.int")
 r.RunMethod2("setHorizontallyScrolling", True, "java.lang.boolean") 
 r.RunMethod2("setEllipsize", "MARQUEE", "android.text.TextUtils$TruncateAt")
 r.RunMethod2("setSelected", True, "java.lang.boolean")

Even though the title of the Actionbar class is a label, setting the above doesn't always work. It never works the first time but if you open the same activity the second time, it works. Similarly if you switch off the screen while in the activity and then turn the phone on again, the text starts scrolling.

Is it possible to set it to scroll all the time? I remember AHActionBar library had this feature working.
 

racerrouthe

Member
Licensed User
Longtime User
I am trying to make the Actionbar title text scroll automatically so that it show longer text. On a label, this is done this way:

B4X:
Dim r As Reflector
 r.Target = TextView
 r.RunMethod2("setLines", 1, "java.lang.int")
 r.RunMethod2("setHorizontallyScrolling", True, "java.lang.boolean") 
 r.RunMethod2("setEllipsize", "MARQUEE", "android.text.TextUtils$TruncateAt")
 r.RunMethod2("setSelected", True, "java.lang.boolean")

Even though the title of the Actionbar class is a label, setting the above doesn't always work. It never works the first time but if you open the same activity the second time, it works. Similarly if you switch off the screen while in the activity and then turn the phone on again, the text starts scrolling.

Is it possible to set it to scroll all the time? I remember AHActionBar library had this feature working.

Have you tried adding a DoEvent ?
 

racerrouthe

Member
Licensed User
Longtime User
Font Issue

Hey Informatix, I have an issue concerning the fontsize, didn't have the issue on my HTC Sensation XL(ICS), but on my Xperia Z (Jellybean) they all of a sudden enlarge very muchScreenshot_2013-05-28-03-09-39.png
 

Informatix

Expert
Licensed User
Longtime User
Hey Informatix, I have an issue concerning the fontsize, didn't have the issue on my HTC Sensation XL(ICS), but on my Xperia Z (Jellybean) they all of a sudden enlarge very muchView attachment 17564

As you can see with the buttons (the blue rectangle is not in the middle), you have customized settings on your device. If I knew what settings you modified (or were modified by the manufacturer), I could do something.
 

racerrouthe

Member
Licensed User
Longtime User
As you can see with the buttons (the blue rectangle is not in the middle), you have customized settings on your device. If I knew what settings you modified (or were modified by the manufacturer), I could do something.

I think it's from the manufactur I haven't changed any defaults :). But I know the problem also exists on Samsung Galaxy S4 so I suspected it to be a prob with Android 4.1 and reflector maybe.
 

racerrouthe

Member
Licensed User
Longtime User
display

Hey Again, did some diging, could it be because of the high resolution 5", 1920x1080 pixels (441 pixels per square inch) ? How to conver 441 ppi ?
 

Informatix

Expert
Licensed User
Longtime User
Hey Again, did some diging, could it be because of the high resolution 5", 1920x1080 pixels (441 pixels per square inch) ? How to conver 441 ppi ?

I found a setting in JellyBean that increases the font size (Settings > Display > Font size). Its default value is Normal.

Another one in Accessibility > Large Text. Should be unchecked.

Maybe there are other settings added by your manufacturer.

That being said, the two settings above should not alter the label size of the class, only the text displayed in the buttons. So I'm still clueless in your case.
 

racerrouthe

Member
Licensed User
Longtime User
Solved

Back Again :) Can't seem to get the toggle button to act right on with the Led but if any is having same issue actionbar then the simple solution is to make a change in the ClsActionBar code. Maybe Informatix could do an update :)

Line to be changed is

lbl.TextSize = Round(ActionBar.Height / 5)

Change it to

lbl.TextSize = Round(ActionBar.Height / (3 * Density))

Then it all looks nice
 

racerrouthe

Member
Licensed User
Longtime User
I found a setting in JellyBean that increases the font size (Settings > Display > Font size). Its default value is Normal.

Another one in Accessibility > Large Text. Should be unchecked.

Maybe there are other settings added by your manufacturer.

That being said, the two settings above should not alter the label size of the class, only the text displayed in the buttons. So I'm still clueless in your case.

Font size is Normal, and Accessibility is unchecked in large text
 

Informatix

Expert
Licensed User
Longtime User
Back Again :) Can't seem to get the toggle button to act right on with the Led but if any is having same issue actionbar then the simple solution is to make a change in the ClsActionBar code. Maybe Informatix could do an update :)

Line to be changed is

lbl.TextSize = Round(ActionBar.Height / 5)

Change it to

lbl.TextSize = Round(ActionBar.Height / (3 * Density))

Then it all looks nice

It's a bug! Thank you for finding it. I will update the class.
 

ciprian

Active Member
Licensed User
Longtime User
Hi there.

I'm trying to add an ProgressBar to replace the "refresh" button.
B4X:
Sub Activity_Create(FirstTime As Boolean)
    'Create 20 items made of a label, button and checkbox.
    Activity.LoadLayout("Main.bal")
   
    AB.Initialize(pnlAB, True, True, pnlAB.Height, Me)
    Dim gd As GradientDrawable, col(2) As Int
    col(0) = Colors.RGB(255, 30, 30)
    col(1) = Colors.RGB(160, 30, 30)
    gd.Initialize("TOP_BOTTOM", col)
    gd.CornerRadius = 8dip
    AB.SetBackground(gd)
    BtnHome = AB.AddButton(LoadBitmap(File.DirAssets, "home.png"), "", 5, 1, "", "Home_LongClick")
    AB.Title.Left = AB.AsPanel.Height + 10dip
    AB.Title.Text = "IPX800 V2"
    AB.Title.TextSize = 20
    AB.AddButton(LoadBitmap(File.DirAssets, "share.png"), "", 5, -1, "", "Share_LongClick")
    'AB.AddButton(LoadBitmap(File.DirAssets, "refresh.png"), "", 5, -1, "", "Refresh_LongClick")
    Dim Pro As ProgressBar
    Pro.Initialize("Pro")
    Pro.Indeterminate = True
    Pro.Visible = False
    AB.AsPanel.AddView(Pro,400,0,100,100)
    AB.AddButton(LoadBitmap(File.DirAssets, "menu.png"), "", 5, -1, "", "Menu_LongClick")
    AB.SetDividerWidth(2dip)
End Sub
I have a button to refresh:
B4X:
Sub ButtonRefresh_click
    Dim Pro As ProgressBar
    Pro.Initialize("Pro")
    Pro.Indeterminate = True
    Pro.Visible = True
End Sub

How can i show the ProgressBar ONLY when clicked on ButtonRefresh ?
 

ciprian

Active Member
Licensed User
Longtime User
Another question: If i create your actionbar in my Main module, it will be showed in other modules?
Or i have to create a second one in the other module?

I'm a newbie...so...dont't be angry if my questions are stupid :)
 
Last edited:
Top