Android Tutorial ActionBar / Sliding Pages tutorial

A simpler and better looking solution is now available:

StdActionBar library allows you to create layouts that use the action bar as a navigation interface.
Note that StdActionBar requires Android 4+.

In this tutorial we will create this layout:


The user can switch pages with a swipe gesture.

StdViewPager holds several panels and supports the swipe gesture.

Using StdViewPager is quite simple:

1. Initialize it and set the number of pages and their size.
2. Add it to its parent.
3. Create the internal pages layouts.

Dim height As Int = CalculateHeight(True, True)
vp.Initialize("vp", 3, 100%x, height) 'vp is a StdViewPager object
Activity.AddView(vp.AsView, 0, 0, 100%x, height)
'load the pages layouts

The next step is to add the ActionBar tabs:
bar.NavigationMode = bar.NAVIGATION_MODE_TABS
bar.AddTab("Tab 1")
bar.AddTab("Tab 2")
bar.AddTab("Tab 3")

We need to synchronize the selected tab and the selected page:
Sub VP_PageSelected (Position As Int)
   If bar.SelectedIndex <> Position Then bar.SelectedIndex = Position
End Sub

Sub bar_TabChanged(Index As Int, STab As StdTab)
   If vp.currentPage <> Index Then vp.ScrollTo(Index, False)
End Sub

CalculateHeight (TabsMode As Boolean, SplitEnabled As Boolean) is a helper sub that calculates the pages height based on the two features.
As you can see in the first screenshot, the split mode is enabled in this case. In split mode the action bar menu items appear at the bottom in portrait mode (phones only). This is set by adding the following line to the manifest editor:
SetApplicationAttribute(android:uiOptions, "splitActionBarWhenNarrow")

The project is attached. Note that it requires StdActionBar v1.50+.


- You can show the "up indicator" by setting ShowUpIndicator to True:


You can then handle the ButtonClicked event and use it to navigate to the "parent" activity.

- The holo.light theme is used in this project. It is done with this manifest line:
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo.Light")


    14.1 KB · Views: 6,805
Last edited:


Well-Known Member
Licensed User
I wanna apply Holo.Dark, but when simply changing in the manifest file an error occurs that it can't be found.
Is that psossible at all / where can i get it ?

Edit: got it - only left the ".ligth", so this works:
SetApplicationAttribute(android:theme, "@android:style/Theme.Holo")
SetApplicationAttribute(android:uiOptions, "splitActionBarWhenNarrow")
Last edited:


Active Member
Licensed User
Hi Erel,


1. show Tab2 when I clicked the Tab1 [world] button.
2. Add [Search] Icon on title ( like youtube )
3. Place the input field on title when clicked the [Search] Icon ( like youtube )
4. Add ItemMenu on title ( like youtube )

How to do that ? Would you help me & give me a example ? Thanks !
Last edited:


Active Member
Licensed User
I get
Compiling code. Error Exception of type 'System.OutOfMemoryException' was thrown.
my ver of b4a is 2.25 using platform 15
What is the wrong ?


Licensed User
The StdViewPager is pretty good. I've been using a 3 panel pager with a transparent panel in the middle to build sliding menus from the left and right sides of the display, with the main content views behind the pager.

A couple of questions:

1) Is there a way to enable or disable paging?
2) Can the speed of the scrollTo method be adjusted?



Licensed User
when activate bar.ShowUpIndicator = True how to get rid of buttonclicked in there to go to some another view or just go to parent of page? (newbe)


Licensed User
yes i knew Erel. how to make code with this small arrow? :) what the name of small arrow? or is the small arrow have an index? is any documentation help for this. thanks you for the fast feedback