first of all i suggest you use :
https://developer.android.com/samples/SlidingTabsBasic/src/com.example.android.common/view/SlidingTabLayout.html
and do not use actionbar tabs.
that is a source code of tabs of google play
app.
after that you can create your own layout use mSlidingTabLayout.setCustomTabView(int layoutResId, int textViewId)
to inflate a custom layout for the SlidingTabLayout tab views. look at:
Android SlidingTabLayout with icons
for complete example.
<?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">
<com.example.android.common.view.SlidingTabLayout
android:id="@+id/sliding_tabs"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<android.support.v4.view.ViewPager
android:id="@+id/viewpager"
android:layout_width="match_parent"
android:layout_height="0px"
android:layout_weight="1"
android:background="@android:color/white"/>
</LinearLayout>
and in your fragment
or activity
:
mViewPager = (ViewPager) view.findViewById(R.id.viewpager);
mViewPager.setAdapter(new MyAdapter());
mSlidingTabLayout = (SlidingTabLayout) view.findViewById(R.id.sliding_tabs);
mSlidingTabLayout.setViewPager(mViewPager);
your adapter of mViewPager
must override below method
@Override
public CharSequence getPageTitle(int position) {
return your tab title;
}
UPDATE:
first step is creating custom layout for each tabs so:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/text1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:gravity="center_vertical"
android:paddingLeft="6dip"
android:minHeight="?android:attr/listPreferredItemHeight"
/>
then when you want to add tabs to actionbar you must do :
ActionBar.Tab tab1=actionBar.newTab();
tab1.setTabListener(this);
tab1.setCustomView(R.layout.tab);
TextView txt1 = (TextView)tab1.getCustomView().findViewById(R.id.text1);
txt1.setText("Tab 1");