Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tabs+Swipe in Android for all API levels

My plan is creating an Activity includes Tabs+Swipe for all Android version. If we set it from a default Android project, it has just support for at least API 11.

In Sherlock we have two project named : Tab Navigation, Tab Navigation(collapsed) includes Tabs but not Swipe. They have Issue #240 in their samples that has a bug (swipe left/right when the tabs are in collapsed mode (landscape) and the selected item does not update).

Do you know any sample code that solve this problem?

like image 612
Ali Avatar asked Dec 24 '12 10:12

Ali


1 Answers

You made this now with the default Android Support Library (or the ABS), with a ViewPager and a PagerTabStrip:

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <android.support.v4.view.PagerTabStrip
            android:id="@+id/tabStrip"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="top"/>

    </android.support.v4.view.ViewPager>

</LinearLayout>

Then create an Adapter to the ViewPager that extends of FragmentStatePagerAdapter (for example) and override the method public CharSequence getPageTitle(int position) to provide a title for each tab.

Hope it helps.

like image 51
sabadow Avatar answered Sep 22 '22 17:09

sabadow