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:

jcesar

Active Member
Licensed User
Longtime User
Its a great lib !

Is there a way to change the action bar color with this lib ?

Regards
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
Its a great lib !

Is there a way to change the action bar color with this lib ?

Regards
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.
 

corwin42

Expert
Licensed User
Longtime User

jcesar

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.

Thanks corwin42

I create a style with actionbar style generator, download and copy the files to res folder. But i dont know how can i use this theme in my b4a project. Can you help me ?

Regards
 

andrewj

Active Member
Licensed User
Longtime User
Hi,
I'm using this in a number of screens where I normally want the action bar hidden, but show it on demand. The problem I have is that if I add the content view with size 100%x, 100%y it doesn't fill the screen, but is still sized to allow for when the action bar is visible. Does anyone know how to set the size of the content views so that they fill the screen, and just shift down (hiding their bottom edge) when I use ABH.Show?

Thanks
Andrew
 

corwin42

Expert
Licensed User
Longtime User
Hi,
I'm using this in a number of screens where I normally want the action bar hidden, but show it on demand. The problem I have is that if I add the content view with size 100%x, 100%y it doesn't fill the screen, but is still sized to allow for when the action bar is visible. Does anyone know how to set the size of the content views so that they fill the screen, and just shift down (hiding their bottom edge) when I use ABH.Show?
This is a bit tricky.

The problem is that Activity.Height is not correct if you hide the ActionBar and you have to correct this value.

With Reflection library you can get the ActionBar height. Then you can recalculate the correct height of the activity

Attached is a small example which shows some buttons always at the bottom of the screen, even if you show/hide the ActionBar.
 

Attachments

  • HideStdActionBarExample.zip
    7.6 KB · Views: 804

andrewj

Active Member
Licensed User
Longtime User
Hi,
Thanks for the help. The code to get the action bar height works fine, but in my example, I don't seem to be able to increase the Activity.Height beyond its default value, whether I try and do so before or after I call ABH.Hide. In my case I have to make this adjustment in Activity_Create, as that's where I define all the client views which need the extra height.

Any ideas?
Thanks
Andrew
 

andrewj

Active Member
Licensed User
Longtime User
Hi,
I got it working. I needed to set the height of all the primary client views as Activity.Height + ActionBarHeight. Then it works.
Thanks for the help
Andrew
 

shashkiranr

Active Member
Licensed User
Longtime User
The described method should still work. I will have a look at the possibility to add a search ActionView to the ActionBar with this library. Should't be too hard to add.

Hi Corwin,

Were you able to add the search dialog to the standard action bar.?

Regards,
SK
 

corwin42

Expert
Licensed User
Longtime User
Hi Corwin,

Were you able to add the search dialog to the standard action bar.?

Yes, problem is that I have currently two libraries doing nearly the same things. One is this StdActionBarHelper library and I have a similar library which uses AppCompat ActionBar. I have to clean both libraries up so they share the same API. The SearchView is currently only in the AppCompat version but I will add it to this Helper library, too.

I need more time for writing B4A libraries... maybe I should quit my job. :)
 

corwin42

Expert
Licensed User
Longtime User
Yes, problem is that I have currently two libraries doing nearly the same things. One is this StdActionBarHelper library and I have a similar library which uses AppCompat ActionBar. I have to clean both libraries up so they share the same API. The SearchView is currently only in the AppCompat version but I will add it to this Helper library, too.

Ok, I tried to add the SearchView to the std. actionbar and I'm stuck on a small problem. Unfortunately B4A doesn't expose the standard android menu api and it is not possible to modify the menu etc. with the normal B4A functionalities. So the only possible way for now to add a standard searchview would be to do it like in my tutorial here. If I remember correctly, with Android 4.0 this will use a search view in the ActionBar.

I'm currently thinking about to write a tutorial on how to make the B4A Menu/ActionItems modifiable and perhaps a method on how to use ActionBarCompat from the support-v7 library with B4A. This is quite complicated and the generated B4A java code must be modified in a #CustomBuildAction for this. So these tutorials will be for the very advanced programmer I guess.
 

shashkiranr

Active Member
Licensed User
Longtime User
Ok, I tried to add the SearchView to the std. actionbar and I'm stuck on a small problem. Unfortunately B4A doesn't expose the standard android menu api and it is not possible to modify the menu etc. with the normal B4A functionalities. So the only possible way for now to add a standard searchview would be to do it like in my tutorial here. If I remember correctly, with Android 4.0 this will use a search view in the ActionBar.

I'm currently thinking about to write a tutorial on how to make the B4A Menu/ActionItems modifiable and perhaps a method on how to use ActionBarCompat from the support-v7 library with B4A. This is quite complicated and the generated B4A java code must be modified in a #CustomBuildAction for this. So these tutorials will be for the very advanced programmer I guess.

Thanks a lot for your effort corwin :) i have tried to write libraries on my own and i know its not a easy job !! :)
 

tipallandgo

Member
Licensed User
Longtime User
I tried to run the example on a Samsung GT-P3110. Sadly, the drawer icon did not replace the up indicator. Does that mean it is included in the devices stated here?
This may not work on all devices (if the device manufacturer changed the ActionBar implementation on the device).
 
Last edited:

corwin42

Expert
Licensed User
Longtime User
I tried to run the example on a Samsung GT-P3110. Sadly, the drawer icon did not replace the up indicator. Does that mean it is included in the devices stated here?

Maybe but I don't really think so. Do you have other apps on this device, where the Navigation drawer works correctly with the three lines icon?
 

tipallandgo

Member
Licensed User
Longtime User
What I have here are the stock apps that comes with the device. I have also updated all the Google apps that is installed. I also updated the device to its latest official firmware from Samsung so it's now running Android 4.1
 

little3399

Active Member
Licensed User
Longtime User
upload_2014-6-6_17-39-49.png
 

little3399

Active Member
Licensed User
Longtime User
upload_2014-6-8_0-4-36.png


HI, I
copy it to your objects\res folder and make all files read-only , and how to set the Theme in the manifest editor ? pls give me a example ? tks!
 

corwin42

Expert
Licensed User
Longtime User
View attachment 25562

HI, I
copy it to your objects\res folder and make all files read-only , and how to set the Theme in the manifest editor ? pls give me a example ? tks!

Please start a new thread with this question because it is not related to this library.

Seems that you try a theme that is designed for ActionBarSherlock.
 
Top