B4A Library StdActionBar - Another ActionBar library

StdActionBar (Standard ActionBar) library is based on the native ActionBar API, therefore it is only supported by Android 4+.

StdActionBar / StdViewPager tutorial: ActionBar / Sliding Pages tutorial

The share of Android 2.x devices is dropping and currently (January 2014) it is only 24%.

This library allows you to add tabs and dropdown list to the action bar:

upload_2014-1-16_17-20-37.png
upload_2014-1-16_17-21-7.png


The attached example demonstrates both modes. You should change the navigation mode to see the two modes.

List mode

Adding a list is very simple. You set the NavigationMode:
B4X:
bar.NavigationMode = bar.NAVIGATION_MODE_LIST
Add the items:
B4X:
bar.SetListItems(Array As String("Dropdown 1", "Dropdown 2", "Dropdown 3"))

And handle the event:
B4X:
Sub bar_ListItemSelected (Index As Int, Value As String)
   Log("Selected value: " & Value)
End Sub

Tabs mode

Unlike TabHost, the tabs do not hold any views. You are responsible for switching the layout based on the selected tab.

The first step is to set the navigation mode:
B4X:
bar.NavigationMode = bar.NAVIGATION_MODE_TABS

Then we add the tabs:
B4X:
bar.AddTab("Tab 1")
bar.AddTab returns a StdTab object. We can use it to modify the tabs:
B4X:
bar.AddTab("Tab 1").Tag = panel1
bar.AddTab("Tab 2").Tag = panel2
'Add icon to tab 3
Dim tb As StdTab = bar.AddTab("Tab 3")
tb.Tag = panel3
Dim bd As BitmapDrawable
bd.Initialize(LoadBitmap(File.DirAssets, "ic_small.png"))
tb.Icon = bd
In the above code we add three tabs and use the tabs tag property to store a panel in each tab. Later we will use these panels to switch the layout.

When the TabChanged event is raised we clear the current layout and show the new layout.
B4X:
Sub bar_TabChanged(Index As Int, STab As StdTab)
   Activity.RemoveAllViews
   Dim pnl As Panel = STab.Tag
   Dim height As Int
   If 100%y > 100%x Then
     height = 100%y - 48dip 'fix for the additional tabs height
   Else
     height = 100%y
   End If
   Activity.AddView(pnl, 0, 0, 100%x, height)
   If pnl.NumberOfViews = 0 Then
     pnl.LoadLayout(Index)
   End If
End Sub

Note that the attached example uses the Holo.Light theme. This is done with this manifest editor line:
B4X:
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")

V1.52 is released. Fixes an incompatibility with Android 5.0. Note that the ButtonClicked event will not work on these devices.

You should use Activity_ActionBarHomeClick event instead.
 

Attachments

  • StdActionBarExample.zip
    11 KB · Views: 2,020
  • StdActionBar.zip
    22.9 KB · Views: 892
Last edited:

bluedude

Well-Known Member
Licensed User
Longtime User

Attachments

  • stdactionbar.png
    stdactionbar.png
    47.3 KB · Views: 271

Bryan

Member
Licensed User
Longtime User
I have set up a menu using Activity.AddMenuItem3. In the application I hide (make invisible) my Main activity panel and call up another one. During this time I would like to disable my menu items on the actionbar so they cannot be clicked on. Is there a way to accomplish this?

Thanks Bryan.
 

bluedude

Well-Known Member
Licensed User
Longtime User
Bryan,

Using that tool but as explained in my thread it won't always work in the correct way. See my post.

It seems nobody has the solution?
 

Bryan

Member
Licensed User
Longtime User
Bryan,

Using that tool but as explained in my thread it won't always work in the correct way. See my post.

It seems nobody has the solution?

It took me several days to figure this all out. I'm no expert in Java and still learning B4A. I do program in a lot of other languages and that does help me out a lot.

I guess one of the biggest things that I had trouble with is what I had to put in the manifest.
This works for me.
B4X:
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")
SetApplicationAttribute(android:theme, "@style/Theme.Tclstyle1")

There are two things done you need the correct Theme (Holo.Light) and then your modified Style for the actionbar. Mine is called Tclstyle1. It was created from the website that was mentioned previously. The actionbar style generator will create a zip file with all the resource files needed. Those are to be put in the res folder of your application. You probably know that already. You may be using the wrong theme. I think using the Dark theme will give you dark menus. There are I believe 3 Holo themes Dark, Light, and Dark/Light combination. There are .xml files that are created with the actionbar generator. I don't think I had to modify any of those. I believe it is the Themes.xml that would be modified if you want to change text color and look other things. Like I said I'm no professional at this, I am always asking for help also.
There was a post on here somewhere where a tutorial was given on how to change styles or themes I think.

In my Theme.xml file I have this to set text color to white.
B4X:
<resources>
<style name="Theme.Tclstyle1" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:textColor">#FFFFFF</item>
Bryan
 
Last edited:

palmzac

Active Member
Licensed User
Longtime User
Hi Erel,

I have no idea. Would you help me & give me a source example ? Thank you very much !

Question
-------------
1. Add [Search] Icon on title ( like youtube )
2. Place the input field on title when clicked the [Search] Icon ( like youtube )
3. Add ItemMenu on title ( like youtube )
 

FireDroid

Member
Licensed User
Longtime User

bluedude

Well-Known Member
Licensed User
Longtime User
Bryan,

That for sure won't work because it changes all text colors and I don't want that. As explained before I have a problem where the drop down list in the actionbar displays a black color for the items. In the style generator you cannot change that.

As said, I have used the correct tools and used the Dark actionbar (I need it). However, that also shows dark text color for the tab list which is wrong in my opinion.

Any other suggestions, Erel?
 

achtrade

Active Member
Licensed User
Longtime User
Hello,

Why is a space in the right edge ?, how can I remove it ?

Thanks.

B4X:
Sub Activity_Create(FirstTime As Boolean)

    bar.Initialize("bar") 
    bar.NavigationMode = bar.NAVIGATION_MODE_LIST 'change to tab to see the other mode
    bar.SetListItems(Array As String("Menu", "Setting", "About"))
    bar.Subtitle = ""
end sub
 

Attachments

  • Screenshot_2014-09-05-11-16-14.png
    Screenshot_2014-09-05-11-16-14.png
    25.3 KB · Views: 275

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello, is it possibile to change the typeface of StdActionBar?
 

seardnA

Member
Licensed User
Longtime User
My appologies for such a newbie question, but where can I download this library? I moved from post to post to page and could find it.
 
Top