Search code examples
androidandroid-actionbarandroid-tabhost

How to get this type of TAB hairline movement


I want to get this type of TAB hairline movement. I am using Action Sherlock Bar in my application's every Tab Activity. I am giving images hope you understand better! I want that when i swipe from 1 Tab Activity to another Tab Activity my hairline over Ta b activity also moves with the tab movement

See i added a capture here In this tab hairline as shown in red box 2nd capture: enter image description here


Solution

  • You can use the Widget like slider tab indicator which is compatible with ViewPager in android.

    Include the PagerSlidingTabStrip widget in your view. This should usually be placed adjacent to the ViewPager it represents.

    <com.astuetz.viewpager.extensions.PagerSlidingTabStrip
    android:id="@+id/tabs"
    android:layout_width="match_parent"
    android:layout_height="48dip" />
    

    In your onCreate method (or onCreateView for a fragment), bind the widget to the ViewPager.

     // Set the pager with an adapter
     ViewPager pager = (ViewPager) findViewById(R.id.pager);
     pager.setAdapter(new TestAdapter(getSupportFragmentManager()));
     // Bind the widget to the adapter
      PagerSlidingTabStrip tabs = (PagerSlidingTabStrip) findViewById(R.id.tabs);
      tabs.setViewPager(pager);
    

    Check out Sample