B4A Library StdActionBarHelper - Utilities for the Standard ActionBar

This library adds some features to the Standard ActionBar. It uses the native ActionBar which is available with Android 3+ (API 11 and above).

The main reason I wrote this library was to add support of changing the up indicator of the actionbar so you can change it to the navigation drawer indicator.

The implementation for this is similar to the one found in the Google Android support library. It uses native methods with API18 and above. If the device has a lower API level a "hack" is used to find the imageview of the up indicator. This may not work on all devices (if the device manufacturer changed the ActionBar implementation on the device).

There are some additional methods to hide the title/appicon etc. from the ActionBar.

With version 1.10 of this library there are many new objects:

ActionMode - Create a contextual ActionBar
Menu and MenuItem - Used to create and modify the menu in the contextual ActionBar
PopupMenu - Create a popup menu like the standard overflow menu.
SearchView - This is for an experimental feature for which I will have to write a new tutorial. With this object it is possible to add a standard SerachView to the ActionBar. But it is quite complicated to use (you will have to change generated B4A Java source etc. So this is really for the advanced user). For now you should ignore this object.

There are a few examples:

ActionModeExample - Example for the contextual ActionBar (ActionMode). This even shows how to modify the menu of the contextual ActionBar.
PopupMenuExample - Show the usage of the PopupMenu object
ActionModePopupExample - Combines ActionMode and Popup Menu
NavDrawerStdActionBarExample - Shows how to use the NavigationDrawer together with the standard ActionBar.

The examples (mainly the NavDrawerExample) use some additional libraries:
- AHNavigationDrawer
- b4amListView
- StdActionBar
- XmlLayoutBuilder
 

Attachments

  • StdActionBarHelper1_10.zip
    16.7 KB · Views: 2,778
  • ActionModeExample.zip
    19.7 KB · Views: 1,844
  • ActionModePopupExample.zip
    20.2 KB · Views: 1,871
  • PopupMenuExample1_00.zip
    15.6 KB · Views: 1,925
  • NavDrawerStdActionBarExample1_2.zip
    328.2 KB · Views: 2,271
Last edited:

ttsolution

Member
Licensed User
Longtime User
Hi all,

I have a listview, I want to show a popup menu when ListView Item clicked. How to achieve that ?

Many thanks

Jonh,
 

ttsolution

Member
Licensed User
Longtime User
Sorry, I'm not sure but my question is related to StdActionBarHelper

B4X:
Dim pop As PopupMenu
pop.Initialize("ListPopup", ButtonAction)    
pop.AddMenuItem(1, "Sales Order", GetDrawable("ic_menu_login"))
pop.AddMenuItem(2, "Take Picture", GetDrawable("ic_action_edit"))
pop.Show

When the ButtonAction is clicked the PopupMenu will be show next to the ButtonAction's anchor.

My question is: I have a listview of Customers and I want to show a PopupMenu right at the line that user tabed, because the second parameter of pop.Initialize("ListPopup", ButtonAction) requires a view. If I code pop.Initialize("ListPopup", myListView) then the PopupMenu always show at the top of myListView.

Appreciate for any help

Jonh,
 

corwin42

Expert
Licensed User
Longtime User
Sorry, I'm not sure but my question is related to StdActionBarHelper

B4X:
Dim pop As PopupMenu
pop.Initialize("ListPopup", ButtonAction)   
pop.AddMenuItem(1, "Sales Order", GetDrawable("ic_menu_login"))
pop.AddMenuItem(2, "Take Picture", GetDrawable("ic_action_edit"))
pop.Show

When the ButtonAction is clicked the PopupMenu will be show next to the ButtonAction's anchor.

My question is: I have a listview of Customers and I want to show a PopupMenu right at the line that user tabed, because the second parameter of pop.Initialize("ListPopup", ButtonAction) requires a view. If I code pop.Initialize("ListPopup", myListView) then the PopupMenu always show at the top of myListView.

Appreciate for any help

Jonh,

In this post you will find a solution to get the view at the ListViews current position. It is old but it still should work.
 

corwin42

Expert
Licensed User
Longtime User
@corwin42
is this library working just on android +3?

Since it uses the standard ActionBar which is only available from Android 3.x: Yes, it works only on Android 3+
 

iglrs1

Member
Licensed User
Longtime User
Hi,

I have tried to test the NavDrawerStdActionBarExample with the additional libs needed but when I copile it I get the following error:

B4A version: 5.20
Parsing code. (0.01s)
Compiling code. (0.03s)
Compiling layouts code. (0.03s)
Generating R file. (0.33s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\nineoldandroid-2.4.0.jar

I have downloaded and copy the nineoldandroid-2.4.0.jar file but still same error. Any help?

Thx
 

corwin42

Expert
Licensed User
Longtime User
B4A version: 5.20
Parsing code. (0.01s)
Compiling code. (0.03s)
Compiling layouts code. (0.03s)
Generating R file. (0.33s)
Compiling generated Java code. Error
Cannot find: C:\Program Files (x86)\Anywhere Software\Basic4android\libraries\nineoldandroid-2.4.0.jar

I have downloaded and copy the nineoldandroid-2.4.0.jar file but still same error. Any help?

Sorry, there was a typo in the AHNavigationDrawer library. Either update to version 1.40 of the library or rename your nineoldandroids-2.4.0.jar to nineoldandroid-2.4.0.jar (without the s). Better update the library.
 

Kwame Twum

Active Member
Licensed User
Longtime User
No. The design of the ActionBar can be changed with a new Theme. You can create your ActionBar design here with the "ActionBar Style Generator". Download the generated Style, copy it to your objects\res folder and make all files read-only or use the new #AdditionalRes attribute.
Then set the Theme in the manifest editor.

Please I tried doing this @corwin42 and everyone, but my app still shows the same old colors..
• Created my theme
• Downloaded it and copied it to my objects\res folder
• Made them all read only
• Set theme in the manifest editor

Currently running Android 5.0. Kindly help out.
 

corwin42

Expert
Licensed User
Longtime User
Please I tried doing this @corwin42 and everyone, but my app still shows the same old colors..
• Created my theme
• Downloaded it and copied it to my objects\res folder
• Made them all read only
• Set theme in the manifest editor

Currently running Android 5.0. Kindly help out.

Which target SDK version do you set in the manifest?

Do you have an example project?
 

Kwame Twum

Active Member
Licensed User
Longtime User
Which target SDK version do you set in the manifest?
Target SDK is 19, I tried 22 and didn't work either.

The project is attached...
 

Attachments

  • ThemeTest.zip
    60.3 KB · Views: 350
Last edited:

Dave O

Well-Known Member
Licensed User
Longtime User
Hi @corwin42

I use PopupMenu in some of my apps, and it generally works great.

However, I just tried to disable a menu item for the first time, and I'm having trouble getting GetItem to work.

Here's the code:
B4X:
dim const PREVIOUS_PAGE as int = 1001
dim const ANOTHER_PROTO as int = 1002

Dim linkMenu As PopupMenu
linkMenu.Initialize("linkMenu", pendingLinkPanel)
Dim bmd As BitmapDrawable
 
bmd.Initialize(LoadBitmap(File.DirAssets, "back32.png"))
linkMenu.AddMenuItem(PREVIOUS_PAGE, "Previous Page", bmd)   'so far, so good

bmd.Initialize(LoadBitmap(File.DirAssets, "another-proto32.png"))
linkMenu.AddMenuItem(ANOTHER_PROTO, "Another Prototype...", bmd)
If common.protoList.Size < 2 Then     'no other prototype to link to
  Dim tempItem As MenuItem = linkMenu.GetItem(ANOTHER_PROTO)
  tempItem.Enabled = False
End If

When it tries to do the GetItem, I get an "index out of bounds" exception on the ItemID. It looks like GetItem is trying to treat ItemID as an index to an array, rather than as a unique ID:

B4X:
java.lang.IndexOutOfBoundsException: Invalid index 1009, size is 2
   at java.util.ArrayList.throwIndexOutOfBoundsException(ArrayList.java:255)
   at java.util.ArrayList.get(ArrayList.java:308)
   at com.android.internal.view.menu.MenuBuilder.getItem(MenuBuilder.java:656)
   at de.amberhome.actionbarhelper.PopupMenuWrapper.GetItem(PopupMenuWrapper.java:102)
   ...

Bug? Or am I missing something here?

Thanks!
 
Last edited:

JohnC

Expert
Licensed User
Longtime User
Weird!

I am using your "ACPopupMenu" to display a pop up menu, but the menu is sometimes randomly popping up in a different location even though I am specifying the SAME/fixed view during initialization:

B4X:
    Pop.Initialize("Popup",  pnlInv)

Any idea why this is happening?
 

DonManfred

Expert
Licensed User
Longtime User
It looks like GetItem is trying to treat ItemID as an index to an array, rather than as a unique ID
It seems you are using the GetItem to get a specific ID instead of using the ARRAY GetItem is using.
You are using GetItem the wrong way.
 

corwin42

Expert
Licensed User
Longtime User
Weird!

I am using your "ACPopupMenu" to display a pop up menu, but the menu is sometimes randomly popping up in a different location even though I am specifying the SAME/fixed view during initialization:

B4X:
    Pop.Initialize("Popup",  pnlInv)

Any idea why this is happening?
No. No such issue is known.

Create an example project which shows this error and post it in the correct thread (for ACPopupMenu use the AppCompat library thread).
 

cxbs

Active Member
Licensed User
Longtime User
Dear Mr. Corwin 42

Thank you for providing such a concise and easy-to-use StdActionBarHelper library.
Can I remove the displayed log information when adding icons?
Thanks again!

The following is the log information:
Set Icon
Set Icons visible
 
Top