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: 894
Last edited:

Myr0n

Active Member
Licensed User
Longtime User
Do you think that, the Action overflow is coming in the next release of the stdactionbar library?

In the meantime, somebody know how to add the action overflow menu to the stdactionbar?
 

Myr0n

Active Member
Licensed User
Longtime User
You are right and I was testing in my samsung galaxy note 10.1 ver 2014, and is just there that does not work.
I tested in my s5 and works very well.

Look the screenshowt of my tablet.
Android version 4.4.2,
Kernel version 3.4.39-1462259

it's definitely my tablet, and I do not know what to do to fix it.

Somebody has the same issue?

I am sorry.
 

Attachments

  • ScreenShot_resize.jpg
    ScreenShot_resize.jpg
    26.1 KB · Views: 229

Myr0n

Active Member
Licensed User
Longtime User
Ups! my bad, I'm definitely an android beginner, sorry.
 

Davin

Member
Licensed User
Longtime User
I have a problem on line
B4X:
bar.Initialize("bar")
bar.NavigationMode =  bar.NAVIGATION_MODE_TABS  '<- this is line 78 copied from Erel Example codes.
and here is the logs:
Error occurred on line: 78 (owneradmin)
java.lang.NullPointerException
at anywheresoftware.b4a.objects.StdActionBar.setNavigationMode(StdActionBar.java:48)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.shell.Shell.runMethod(Shell.java:485)
at anywheresoftware.b4a.shell.Shell.raiseEventImpl(Shell.java:229)
at anywheresoftware.b4a.shell.Shell.raiseEvent(Shell.java:174)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at anywheresoftware.b4a.ShellBA.raiseEvent2(ShellBA.java:93)
at com.memoryforever.metsoft.owneradmin.afterFirstLayout(owneradmin.java:98)
at com.memoryforever.metsoft.owneradmin.access$100(owneradmin.java:16)
at com.memoryforever.metsoft.owneradmin$WaitForLayout.run(owneradmin.java:76)
at android.os.Handler.handleCallback(Handler.java:725)
at android.os.Handler.dispatchMessage(Handler.java:92)
at android.os.Looper.loop(Looper.java:137)
at android.app.ActivityThread.main(ActivityThread.java:5171)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:511)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:797)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:564)
at dalvik.system.NativeStart.main(Native Method)
** Activity (main) Resume **
--------- beginning of /dev/log/system
i pretty much get the same error message too
 

RandomCoder

Well-Known Member
Licensed User
Longtime User
Check to make sure that you haven't set IncludeTitle to false in the Activity attributes.
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
everytime I do:

B4X:
SlidePage.Initialize("SlidePage", 3, 100%x, 100%y)

I have this error:
java.lang.NoClassDefFoundError: android.support.v4.view.ViewPager

Obviously I have already copied the file android-support-v4.jar into the additional lib folder.
Please help
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
It's the file in the first post
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
I referred to the StdActionBar library.
If you think that my android-support-v4 file is corrupted, please I need this file, because I've already downloaded from the SDK
 

MarcoRome

Expert
Licensed User
Longtime User
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:

View attachment 22024 View attachment 22025

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. An alternative way to add this event will be added in the next version of B4A.

if i want add :

B4X:
     AdView1.Initialize2("Ad", "ca-app-pub-7335111176005677/2XXXXXX", AdView1.SIZE_SMART_BANNER)
     If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
      'phones
     If 100%x > 100%y Then height = 32dip Else height = 50dip
         Else
      'tablets
      height = 90dip
     End If
     Activity.AddView(AdView1, 0dip, 100%y - height, 100%x, height)
     AdView1.LoadAd

i dont see nothing also if i change:

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 = 80%y '<----------------------- ALSO IF CHANGE THIS 80%y
   End If
   Activity.AddView(pnl, 0, 0, 100%x, height)
   Activity.AddView(AdView1, 0dip, 100%y - height, 100%x, height) '<--- Add this
   AdView1.LoadAd
   If pnl.NumberOfViews = 0 Then
     pnl.LoadLayout(Index)
   End If
End Sub
Any idea ??
Thank you
 

MarcoRome

Expert
Licensed User
Longtime User
How is this code related to StdActionBar?
Hi Erel, yes i have this code:

in activity_create

B4X:
'Activity.LoadLayout("information_phone")
'Per Pubblicità
    AdView1.Initialize2("Ad", "ca-app-pub-7335111176005677/2xxxxxx", AdView1.SIZE_SMART_BANNER)
     If GetDeviceLayoutValues.ApproximateScreenSize < 6 Then
      'phones
     If 100%x > 100%y Then height1 = 32dip Else height1 = 50dip
        Else
      'tablets
      height1 = 90dip
     End If
'    Activity.AddView(AdView1, 0dip, 100%y - height, 100%x, height)
'    AdView1.LoadAd
'Fine Pubblicita
....
'Menu
    bar.Initialize("bar")
    bar.NavigationMode = bar.NAVIGATION_MODE_TABS 'change to list to see the other mode
    Activity.Title = "SIM Card PRO"
    bar.Subtitle = "By Devil-App"
  
    Activity.AddMenuItem3("MenuItem", "mi", LoadBitmap(File.DirAssets, "ic_action_share.png"), True)
    panel1.Initialize("")
    panel2.Initialize("")
    'panel1.Height = 90


    bar.AddTab("INFO SIM CARD").Tag = panel1
    bar.AddTab("CONTACT").Tag = panel2
  
    If bar.NavigationMode = bar.NAVIGATION_MODE_TABS Then
        'set the current selected tab
        bar.SelectedIndex = currentTab
        If currentTab = 0 Then bar_TabChanged(currentTab, bar.SelectedTab)
    End If

and in another event this code:

B4X:
Sub bar_TabChanged(Index As Int, STab As StdTab)
    Activity.RemoveAllViews
    Dim pnl As Panel = STab.Tag
    pnl.Color = Colors.Black <---- This is color black pnl
    Dim height As Int
    If 100%y > 100%x Then
        height = 100%y - 48dip
    Else
        height = 90%y
    End If
'    Activity.AddView(pnl, 0, 0, 100%x, height)
    Activity.AddView(pnl, 0, 0, 100%x, 80%y)
    Activity.AddView(AdView1, 0dip, 100%y - height1, 100%x, height1)
    AdView1.LoadAd
    If pnl.NumberOfViews = 0 Then
        pnl.LoadLayout(Index)
    End If
End Sub

Now the problem when start Adview i see this.. but in background...as if it were on a panel ( ?? ) look pictures
per erel.jpg


Thank you for your support.
 
Last edited:
Top