Android Tutorial TabStripViewPager - Better ViewPager

Status
Not open for further replies.

This library is based on the following open source project: https://github.com/astuetz/PagerSlidingTabStrip
License: http://www.apache.org/licenses/LICENSE-2.0

It is an alternative to StdViewPager. It is simpler to use and looks better.
It is implemented as a custom view. It requires B4A v5.8+.

It is very simple to add a TabStrip to your app.

Add the TabStrip with the visual designer and configure it:

SS-2016-02-25_15.22.50.png


Note the usage of anchors to fill the available space.

Create a layout file for each page. Again use anchors to fill the available space:

SS-2016-02-25_15.24.22.png


Load the main layout and then add pages with a call to TabStrip.LoadLayout:
B4X:
Sub Activity_Create(FirstTime As Boolean)
   Activity.LoadLayout("Main")
   TabStrip1.LoadLayout("Page1", "PAGE 1")
   TabStrip1.LoadLayout("Page2", "THIS IS PAGE 2")
   TabStrip1.LoadLayout("Page3", "AND PAGE 3")
End Sub

Add the following text to the manifest editor (it creates the short press effect):
B4X:
'********* TabStrip ***********************
CreateResource(drawable, background_tab.xml,
<selector xmlns:android="http://schemas.android.com/apk/res/android"
   android:exitFadeDuration="@android:integer/config_shortAnimTime">
  <item android:state_pressed="true" android:drawable="@color/background_tab_pressed" />
  <item android:state_focused="true" android:drawable="@color/background_tab_pressed"/>
  <item android:drawable="@android:color/transparent"/>
</selector>)
CreateResource(values, colors.xml,
<resources>
  <color name="background_tab_pressed">#6633B5E5</color>
</resources>)
'******************************************

If you are using B4A v6+ then you should add this line:
B4X:
#AdditionalJar: com.android.support:support-v4

As Android support library requires Android 4+ (API level 14+), TabStripViewPager also requires Android 4+.
 

Attachments

  • TabStripExample.zip
    10.9 KB · Views: 3,395
  • TabStripViewPager_Library.zip
    30.5 KB · Views: 2,585
Last edited:

ArminKH

Well-Known Member
what is the difference with Design Support Tab Layout?
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
what is the difference with Design Support Tab Layout?
This is based on a different native library. As TabStrip is implemented as a custom view it is very simple to add it.

Note that unlike StdActionBar you can add multiple TabStrips to the activity (or any Panel).
 

so27

Active Member
Licensed User
Longtime User
Great, on something I've been waiting.
 

phukol

Active Member
Licensed User
Longtime User
Just want to ask how can i access each individual panel generated by the tabstrip?
I am trying to make use of a single layout and set the values of each view differently for each panel,
 
Last edited:

susu

Well-Known Member
Licensed User
Longtime User
How can I create TabStrip by using code without load layout? Thanks.
 

Mahares

Expert
Licensed User
Longtime User
@Erel claims it is a better viewpager. Let us see if he can accommodate these requests as I would like to use it as an alternate to AHViewPager which is excellent :
1. Can you add a way to be able to hide one or more pages when the program requires fewer. For instance, some data input is on one page that is not needed for a given item, but will be needed for another.
2. Can you add the ability to change the pages titles text size, font and typeface.
3. Can you provide the ability to change the color of the selected page horizontal line indicator besides black.
4. Can you make it where a change in the pages title background color is possible.
5.. I attempted to apply it to an application that uses AHViewPager, the program folder increased from 2.2 MB to 4.8 MB despite removing all the AHViewPager code and libraries. The apk went from 350 KB to 850 KB. That is too much wasted real estate.

Based on @Erel's answers, I will decide if it is actually better for me than AHViewPager.
Thank you for innovating.
 

Giovanniluca Vuono

Member
Licensed User
Longtime User
Hi Everyone, thanks to Erel for this great lib.. I've some questions:
Is it possible to add Anotherdatepicker to the first tab or scrollview in the second tab?
Can I add a StartActivity("Activity") to a tab or I can only load a Layout?
 

DonManfred

Expert
Licensed User
Longtime User
Can I add a StartActivity("Activity") to a tab or I can only load a Layout?
It´s up to you what you do when clicking a button. You can for sure call another activity

You can not use different activities in the tabs. ALL TABS are in ONE activity. The one where the tabstrip belongs to.
 

Giovanniluca Vuono

Member
Licensed User
Longtime User
Add a Anotherdatepicker to the layoutfile for first tab
Add a Scrollview to the layoutfile for second tab.
Yes, I've already done it..
But if I want to fill a table in the second tab with SQLite where can I add the logic? I can insert the logic in an activity not in a layout..
 

Erel

B4X founder
Staff member
Licensed User
Longtime User
@Erel claims it is a better viewpager
I was comparing it to the StdViewPager solution.
The library itself is small, however it depends on android-support-v4.jar. If you weren't using it before then it will add about 400kb to the APK.

Use whichever solution you find best for you.
 

Mahares

Expert
Licensed User
Longtime User
I was comparing it to the StdViewPager solution.
@Erel: Any plans to enhance it and add the functionality that I posted in Post#12. As you know, many library developers come and go and we are stuck with many libraries without support, but in in your case we have a sense of security that you will be there for us in case of need. If not, perhaps post the library code here so someone with lib knowledge can enhance it.
 
Status
Not open for further replies.
Top