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

Fusseldieb

Active Member
Licensed User
Longtime User
There is anyway to add this function with appcompact libray ? i tryed but it doesnt seems to be working very well, I really would like to see this function with Material Design... Any suggestion? Thanks
 

Jose Luis Barajas

Member
Licensed User
Longtime User
Hello

After upgrade my Phone to Android 5.1.1

Event in action bar doesn't work, Event not fired, Any body can help, or this library needs an update for this Android version?

Sub bar_buttonclicked
sm.ShowMenu
End Sub
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
Hello,
when I initialize an StdViewPager, I get this error log.. Please, can you help?


B4X:
Private vp As StdViewPager
vp.Initialize("vp", 4, 100%x, height)
Activity.AddView(vp.AsView, 0, 0, 100%x, height)


** Activity (main) Create, isFirst = true **


Device name: cell_0607970a


Device name: cell_0607970a
sending message to waiting queue of uninitialized activity (registerdevice)


java.lang.NoClassDefFoundError: Failed resolution of: Landroid/support/v4/view/ViewPager;


    at anywheresoftware.b4a.objects.StdActionBar$StdViewPager.Initialize(StdActionBar.java:349)
    at it.simone.biliato.csifortitudovedelago.main._activity_create(main.java:357)
    at java.lang.reflect.Method.invoke(Native Method)
    at java.lang.reflect.Method.invoke(Method.java:372)
    at anywheresoftware.b4a.BA.raiseEvent2(BA.java:174)
    at it.simone.biliato.csifortitudovedelago.main.afterFirstLayout(main.java:98)


    at it.simone.biliato.csifortitudovedelago.main.access$100(main.java:16)
    at it.simone.biliato.csifortitudovedelago.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:145)
    at android.app.ActivityThread.main(ActivityThread.java:5832)
    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:1399)
    at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1194)
Caused by: java.lang.ClassNotFoundException: Didn't find class "android.support.v4.view.ViewPager" on path: DexPathList[[zip file "/data/app/it.simone.biliato.csifortitudovedelago-1/base.apk"],nativeLibraryDirectories=[/vendor/lib, /system/lib]]
    at dalvik.system.BaseDexClassLoader.findClass(BaseDexClassLoader.java:56)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:511)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:469)
    ... 16 more
    Suppressed: java.lang.ClassNotFoundException: android.support.v4.view.ViewPager
        at java.lang.Class.classForName(Native Method)
        at java.lang.BootClassLoader.findClass(ClassLoader.java:781)
        at java.lang.BootClassLoader.loadClass(ClassLoader.java:841)
        at java.lang.ClassLoader.loadClass(ClassLoader.java:504)
        ... 17 more
    Caused by: java.lang.NoClassDefFoundError: Class not found using the boot class loader; no stack available
 

imgsimonebiliato

Well-Known Member
Licensed User
Longtime User
You need to download android-support-v4.jar from Android SDK Manager and copy it to the additional libraries folder.
I've already done it, but nothing
 

trueboss323

Active Member
Licensed User
Longtime User
I wasn't sure that you were using it. It is not possible to make the indicator slide with this library (there is no such built-in feature in Android).

Some example of apps that are using this include WhatsApp , Google Play, YouTube. When you are swiping the screen to switch tabs, you will notice the tab indicator bar also slides with it. Is there a way I can put this same functionality with my app?
 

corwin42

Expert
Licensed User
Longtime User
Some example of apps that are using this include WhatsApp , Google Play, YouTube. When you are swiping the screen to switch tabs, you will notice the tab indicator bar also slides with it. Is there a way I can put this same functionality with my app?

The feature of the sliding tab indicator is only available with the Design Support Library.
 

Douglas Farias

Expert
Licensed User
Longtime User
@Erel
i see you changed the first post.


1 - this lib will not run on android 3+?
I see on a lot of places on internet the action bar minimal api its 11 Android 3+
why this lib run only on Android 4+?



2 - How to change the indicator icon?
a5YE9.jpg


i need the first next the book icon. 3 Lines

I m tryed the 3 modes NAVIGATION_MODE_STANDARD etc and dont work i see only (<) icon
like the search the dictionary image.


How can i make like this

222.png


images.png



I m tested all modes on my device and the result is only this icon <-

thumb-LED-Lollipop2-8dae5ad04e9c013182733d815be4cf94.jpg


this is another mode this and its not listed on this lib?
via JavaObject its possible change this icon or mode?
Can you give one example how change this?


Many thx
 
Last edited:

Myr0n

Active Member
Licensed User
Longtime User

irda

Member
Licensed User
Longtime User
I update my proyect to the new versión of b4a 5.80 from 3.x and now I have the next compiler error:

B4A version: 5.80
Parsing code. (0.10s)
Compiling code. (0.08s)
Compiling layouts code. (0.03s)
Generating R file. Error
AndroidManifest.xml:23: error: Error: No resource found that matches the given name (at 'theme' with value '@style/Theme.Custombar').

Can't I use the same proyect?
 
Top