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: 2,287
  • TabStripViewPager_Library.zip
    30.5 KB · Views: 1,478
Last edited:

achtrade

Active Member
Licensed User
Now you need to compare the example with your project.

I did it and I didn't find any difference, you can see in the previous pictures what I have in my project, everything is the same.

What else could be ?
 

MCU01

Member
Licensed User
Hi. I'm having a similar problem that other people are having. I'm trying to update my Android-SDK-Manager with the latest updates, but I'm not sure which one in particular is the update that I need. Thanks in advance for your help.



upload_2017-4-10_2-7-54.png


upload_2017-4-10_2-13-30.png
 

MCU01

Member
Licensed User
Okay. Here they are,

B4A version: 6.50
Parsing code. (0.04s)
Compiling code. (0.07s)
Compiling layouts code. (0.01s)
Organizing libraries. Error
Maven artifact not found: com.android.support/support-v4
 

jkhazraji

Active Member
Licensed User
I get this error on running @Erel Example:

Error.png

Generating R file. Error
res\values-v20\theme.xml:3: error: Error retrieving parent for item: No resource found that matches the given name '@android:style/Theme.Material.Light'.
The contents of res\values-v20\theme.xml look like:

<?xml version="1.0" encoding="utf-8" ?>
- <resources>
<style name="LightTheme" parent="@android:style/Theme.Material.Light" />
</resources>

What is causing the error??
 

bigbadfred

Member
Licensed User
Just wanted to say thanks to Erel, because I changed my other viewpager with this one and I could replace 40 lines of code with just one.
I love to keep things simple...
 

ilan

Expert
Licensed User

ilan

Expert
Licensed User
Which event are you seeing in the Java code?

I think those are events :D (java is not my native language)

onPageScrollStateChanged
onPageScrolled

Will they raise after the tabstrip page select animation is finished and the page is visible?

The PageSelected event (that is available in b4a) will raise when you select the page and on scrolling it happens before the page scroll animation is finished.

Thank you
 
Status
Not open for further replies.
Top