Custom Android Tab View

I am adding tabs to my application using this code:

ActionBar.Tab tab1=actionBar.newTab();
tab1.setTabListener(this);
tab1.setCustomView(R.layout.tab_style);
TextView txt1 = (TextView)tab1.getCustomView().findViewById(R.id.tabtext);
txt1.setText(R.string.tab_1);
actionBar.addTab(tab1);

And this is tab_style.xml

<?xml version="1.0" encoding="utf-8"?>
<!-- This is the main layout of the application -->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/fragment_basic_root"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@color/white" 
    android:paddingBottom="15dp"
    >


<TextView
    android:id="@+id/tabtext"
    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"
    android:textSize="20dp"
/>
</RelativeLayout>

I want to change the background of the tab, but the result:

enter image description here

How can i fix this? Customview is not centered.

+4
source share
2 answers

action bar tabs are outdated in the L. developers preview

the black area is the background actionBar tabBar. You must create a style actionBarTabBarStyleand set its background. look at this link:

http://blog.alwold.com/2013/08/28/styling-tabs-in-the-android-action-bar/

or you can use another library, for example:

PagerSlidingTabStrip

Google, :

SlidingTabsBasic

+2

,

0

All Articles