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: 1,999
  • StdActionBar.zip
    22.9 KB · Views: 871
Last edited:

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
But if I set 32x32, images are blurred :(
 

Silli

Member
Licensed User
Longtime User
The Library returns "java.lang.NoSuchFieldException:mActionView" in the L Developer Preview

Is there any way to fix it?

You will need to remove the ButtonClick event. This issue will be fixed. It seems like there is a problem in Android L Preview where the action bar icon doesn't appear at all. I wasn't able to find any documentation about it. So I don't know whether they removed it on purpose or it is a bug.

The problem occurs too in the final Android 5 (Android L) SDK. Is a solution in planning?
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
looking at the picture.
The 3 tab A, B, C in some devices, the are positioned near the word "CSI" and in other ones they are below. So, I placed a list and I have no idea how to manage the layout LIST HEIGHT due to this different for device. Any idea?

EDIT: Picture attacched
 

Attachments

  • 1.png
    1.png
    15.2 KB · Views: 203
Last edited:

ggpanta

Member
Licensed User
Longtime User
Do you see an action bar icon?
Erel the bar is created as well the actionbar icon.

B4X:
java.lang.NoSuchFieldException: mActionView
    at java.lang.Class.getDeclaredField(Class.java:886)
    at anywheresoftware.b4a.objects.StdActionBar.Initialize(StdActionBar.java:64)
    at com.sshlroot.pbminingstats.main._setupgui(main.java:2774)
    at com.sshlroot.pbminingstats.main._activity_create(main.java:367)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:175)
    at com.sshlroot.pbminingstats.main.afterFirstLayout(main.java:98)
    at com.sshlroot.pbminingstats.main.access$100(main.java:16)
    at com.sshlroot.pbminingstats.main$WaitForLayout.run(main.java:76)
    at android.os.Handler.handleCallback(Handler.java:739)
    at android.os.Handler.dispatchMessage(Handler.java:95)
    at android.os.Looper.loop(Looper.java:135)
    at android.app.ActivityThread.main(ActivityThread.java:5221)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:899)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:694)

Tested on a Nexus 7 (2013) on Lollipop
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
looking at the picture.
The 3 tab A, B, C in some devices, the are positioned near the word "CSI" and in other ones they are below. So, I placed a list and I have no idea how to manage the layout LIST HEIGHT due to this different for device. Any idea?

EDIT: Picture attacched

Please
 

Erel

B4X founder
Staff member
Licensed User
Longtime User

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Got this error:
B4X:
AndroidManifest.xml:14: error: No resource identifier found for attribute 'uiOptions' in package 'android'
 

Antony Danby

Member
Licensed User
Longtime User
Erel,

Hi

I am writing an application and I am using a StdActionBar and a StdViewPager and I want to have Preferences as one of the Panels.

So, kind of like this :-

Sub Globals
Private bar As StdActionBar
Private vp As StdViewPager
End Sub

In another routine:

'Load the pages layouts
vp.Panels(0).LoadLayout("0")
vp.Panels(1).LoadLayout("1")
vp.Panels(2).LoadLayout("2")

Panel / Page 2 is ( or will be ) the Preferences page.
There are a lot of settings, so how would I make this Panel / Page scrollable ?

Sorry if this is a stupid question, I am a bit of a B4A newbie

Thanks
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
You can scroll the view to the page 2 when your Activity Start:

B4X:
vp.ScrollTo(1, True)
 

Antony Danby

Member
Licensed User
Longtime User
You can scroll the view to the page 2 when your Activity Start:

B4X:
vp.ScrollTo(1, True)

Not what I meant. I meant scrollable up and down ON THE ACTUAL PAGE, not to scroll to a page.
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Last edited:

ggpanta

Member
Licensed User
Longtime User

Attachments

  • Screenshot_2014-10-22-05-44-20.png
    Screenshot_2014-10-22-05-44-20.png
    40.4 KB · Views: 191

Erel

B4X founder
Staff member
Licensed User
Longtime User
There are a lot of settings, so how would I make this Panel / Page scrollable ?
Add a ScrollView to the Panel.

It doors work without the ButtonClicked event but I need it to open my nav drawer. I will wait for the updated library.
This issue will be solved in the next update of B4A.
 
Last edited:

ggpanta

Member
Licensed User
Longtime User
Add a ScrollView to the Panel.


This issue will be solved in the next update or B4A.

Is it possible to add transparency to the action bar? I know I can theme it and I am using xml for that but I would like to change the transparency to simulate the effect on the play store, ie change the actionbar alpha while my scrollview is scrolled up.
 

ggpanta

Member
Licensed User
Longtime User
The problem with that is that the transparency is set to that alpha value, you cant change it after.

My Idea is to have the actionbar at 0 and change it gradually to 255 while the user scrolls the scrollview, that way the actionbar will dissapear.

The other issue is that to my understanding this actionbar is ocupying always the top part of the activity, thus I cant have it overlap part of my UI. If this was possible I could add the scrollview at top(0) of the activity overlaped by the actionbar (I will add any views lower in that scrollview), that way when the actionbar becomes transparent the views in the scrollview would be visible.

Check how it appears in the play store when you sroll down on an item decription, the actionbar gradually dissapears (fades out), and the content is shown underneath the previous visible actionbar.
 
Top