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

tamayo461

Member
Licensed User
Longtime User
where download Reflector lib?

the error is:


Compiling code. Error
Error parsing program.
Error description: Unknown type: reflector
Are you missing a library reference?
Occurred on line: 535
Dim r As Reflector


:(:(:(:(
 

SCIS

Active Member
Licensed User
Longtime User
Dear users of the ActionBar class,

Me and some other students are making an Android app for school, which is deciding whether we can pass our year or not (we study ICT).

Currently, we made a draft in Photoshop for how we want the layout to be, as included in this post. I was wondering if the titlebar as you can see in the image, is possible with this class? Because I couldn't manage to do it with the default titlebar in B4A.

I also want to mention that me and the other students are new at B4A and we recently purchased it, like a month ago.

Thanks in advance,

SCIS.
 

Attachments

  • gip-startscherm-met-gast.jpg
    gip-startscherm-met-gast.jpg
    34.7 KB · Views: 374

Informatix

Expert
Licensed User
Longtime User
Dear users of the ActionBar class,

Me and some other students are making an Android app for school, which is deciding whether we can pass our year or not (we study ICT).

Currently, we made a draft in Photoshop for how we want the layout to be, as included in this post. I was wondering if the titlebar as you can see in the image, is possible with this class? Because I couldn't manage to do it with the default titlebar in B4A.

I don't think you need this class. A simple panel should be enough, with an ImageView and a Label inside. If you plan to add buttons in this title bar, the ActionBar class may become useful.
 

AllanH

Member
Licensed User
Longtime User
Hide official actionbar and use yours

I have an app (EchoCalc) that uses two menu items. It works fine on my old HTC Desire with its menu key and only displays a menu when you press menu.
With an HTC One S, the actionbar appears at the bottom of the screen all the time but this hides some of my activity.
This has not been reported in other phones (my app has been used in hundreds of models and downloaded thousands of times).
If I don't add any menus, the actionbar is still visible but is empty save the 3 white dots in the middle of the screen.
I have tried to remove the actionbar with

Dim r As Reflector
If ApiBuildVersion > 10 Then
r.Target = r.GetActivity
r.Target = r.RunMethod("getActionBar")
If r <> Null Then r.RunMethod ("hide")

but I get an exception when it does the RunMethod (null pointer).

How do I get ride of the official actionbar and then I can look at using yours instead!

Allan
 

Informatix

Expert
Licensed User
Longtime User
I have an app (EchoCalc) that uses two menu items. It works fine on my old HTC Desire with its menu key and only displays a menu when you press menu.
With an HTC One S, the actionbar appears at the bottom of the screen all the time but this hides some of my activity.
This has not been reported in other phones (my app has been used in hundreds of models and downloaded thousands of times).
If I don't add any menus, the actionbar is still visible but is empty save the 3 white dots in the middle of the screen.
I have tried to remove the actionbar with

Dim r As Reflector
If ApiBuildVersion > 10 Then
r.Target = r.GetActivity
r.Target = r.RunMethod("getActionBar")
If r <> Null Then r.RunMethod ("hide")

but I get an exception when it does the RunMethod (null pointer).

How do I get ride of the official actionbar and then I can look at using yours instead!

Allan

I suppose you have a phone under Gingerbread and the guy with the HTC One S has a more recent system (ICS or Jelly Bean) on his device. What you see at the bottom is the navigation bar (the action bar is always above) and it does not hide anything (theoretically). You can remove it but since you cannot occupy the empty space and the bar reappears instantly when you touch the screen, it's useless to remove it.
About your question: my class is not for the navigation bar, but for the action bar (above the activity). It replaces the title bar.
 

SCIS

Active Member
Licensed User
Longtime User
Hello,

Currently what I want to do is, add a button with my logo in it, but still being able to use the tab_selected.png over it. I can't seem to manage that. Basicly, I want to put my logo in the Home button instead of the text, "Home", it has.
My current code looks like this:
B4X:
   AB.Initialize(pnlAB, True, True, pnlAB.Height, Me)
   LastTab = AB.AddButton(LoadBitmap(File.DirAssets, "tab_selected.png"), "Home", 5, 1, "Home_Click", "")
   AB.SetIconAsWideAsText(True)
   AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Search", 5, 2, "Search_Click", "")
   AB.AddButton(LoadBitmap(File.DirAssets, "tab_normal.png"), "Menu", 5, 3, "Menu_Click", "")
   AB.SetDividerWidth(2dip)
   AB.SameWidthForAll(True)

If anyone can tell me how I can manage this, I will be very thankful.

Greetings,
SCIS.
 

Informatix

Expert
Licensed User
Longtime User
Hello,

Currently what I want to do is, add a button with my logo in it, but still being able to use the tab_selected.png over it. I can't seem to manage that. Basicly, I want to put my logo in the Home button instead of the text, "Home", it has.
My current code looks like this:
B4X:
...

If anyone can tell me how I can manage this, I will be very thankful.

You have to modify AddButton in the class code if you want to display a bitmap instead of a text (you set the label background instead of the label text). You'll probably have to modify also ResizeButton.
 

asiammyself

Member
Licensed User
Longtime User
Hello great class here. Wondering if I could add two images per button? for example I'm trying to have a mix of the Tab style and menu style. For example I would have icons then text under it and also the little image showing its selected like in the tab style. I saw in your tutorial that you have something like this but I'm looking to have the buttons be equal size and fill the screen.

I'm I confusing anyone? I could post photoshop if needed. Not looking for anyone to write the code for me. Just trying to understand how it would be done. Thanks in advance.
 

Informatix

Expert
Licensed User
Longtime User
Hello great class here. Wondering if I could add two images per button? for example I'm trying to have a mix of the Tab style and menu style. For example I would have icons then text under it and also the little image showing its selected like in the tab style. I saw in your tutorial that you have something like this but I'm looking to have the buttons be equal size and fill the screen.

I'm I confusing anyone? I could post photoshop if needed. Not looking for anyone to write the code for me. Just trying to understand how it would be done. Thanks in advance.

You have the source code so change it as you wish.
 

asiammyself

Member
Licensed User
Longtime User
Just for anyone looking to do what I'm trying to do. Instead of modifying the class I made two actionbars right below the other. The first one has an icon and text while the second actionbar as an icon fit to stretch. When the icon with text is clicked it runs a function which replaces the second actionbar with the highlight tab image. Figured it was a simpler way to do it rather then diving into the class.:)
 

NeoTechni

Well-Known Member
Licensed User
Longtime User
The Google Plus has a really nice dropdown menu in it's action bar, I don't suppose you could add support for that?
 

lock255

Well-Known Member
Licensed User
Longtime User
Informatix please i need your help. I can not call the activity when I click on the images dell'ActionBar. I call the activity in this way:

B4X:
Sub Info_LongClick(ActionBar As ClsActionBar, Btn As View)
   StartActivity(Main2)
End Sub


I have tried both in release and debug mode that always gives me this error: Application (Pippo) has stopped unexpectedly. Try ...
I conducted the tests directly on the file that you provided without adding other codes. Do you have any idea to solve this problem?
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
Informatix please i need your help. I can not richimare the activity when I click on the images dell'ActionBar. I richimato the activity in this way:

richimare, dell, richimato ??? What's language is it? Italiano? Please, try to speak only in english.

B4X:
Sub Info_LongClick(ActionBar As ClsActionBar, Btn As View)
   StartActivity(Main2)
End Sub
I have tried both in release and debug mode that always gives me this error: Application (Pippo) has stopped unexpectedly. Try ...
I conducted the tests directly on the file that you provided without adding other codes. Do you have any idea to solve this problem?

I can't see what the problem is. I don't have any problem to start another activity with a long click on a button.
You should post your code.
 

lock255

Well-Known Member
Licensed User
Longtime User
I apologize for forgetting to translate into English.
In attachment I put your project with a startActivity in pulsed share. When click pulsed Share on me the error described above.
 
Last edited:

Informatix

Expert
Licensed User
Longtime User
I apologize for forgetting to translate into English.
In attachment I put your project with a startActivity in pulsed share. When click pulsed Share on me the error described above.

File: http://www.hizlog.com/extra/ActionBar.zip

I tried your example on different devices with different OS (Gingerbread, ICS, JB). None had a problem with it. The second activity opens without any error.
 
Top