Try to use like following
TabWidget tabWidget = getTabWidget();
TabHost tab = getTabHost();
tab.setOnTabChangedListener(new OnTabChangeListener() {
public void onTabChanged(String arg0) {
for (int i = 0; i < tab.getTabWidget().getChildCount(); i++) {
tab.getTabWidget().getChildAt(i)
.setBackgroundResource(R.drawable.tab_selected); // unselected
}
tab.getTabWidget().getChildAt(tab.getCurrentTab())
.setBackgroundResource(R.drawable.tab_unselected); // selected
}
});
Intent intent = new Intent(FromClass.this,
ToClass.class);
TabSpec tabpiechartActivity = tab.newTabSpec("Name")
.setIndicator(prepareIndicator("Name"))
.setContent(intent);
and your prepareIndicator
will be
private View prepareIndicator(String string) {
View view = LayoutInflater.from(this).inflate(R.layout.customtab, null);
// ImageView iv = (ImageView) view.findViewById(R.id.TabImageView);
TextView tv = (TextView) view.findViewById(R.id.tabText);
// iv.setImageResource(resId);
tv.setText(string);
return view;
}
And your res/layout/customtab
xml is:
<?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:background="@drawable/tab_selected"
android:orientation="vertical" >
<TextView
android:id="@+id/tabText"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:textColor="#ffffff"
android:textSize="15dp" />
</LinearLayout>
And res/drawable/tab_selected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<gradient
android:angle="225"
android:endColor="#11029E"
android:startColor="#DD000000" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="7dp"
android:radius="0.1dp"
android:topLeftRadius="0dp"
android:topRightRadius="7dp" />
</shape>
And res/drawable/tab_selected.tab_unselected.xml
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<stroke
android:width="1dp"
android:color="#FFFFFFFF" />
<gradient
android:angle="225"
android:endColor="#0F7801"
android:startColor="#DD000000" />
<corners
android:bottomLeftRadius="0dp"
android:bottomRightRadius="7dp"
android:radius="0.1dp"
android:topLeftRadius="0dp"
android:topRightRadius="7dp" />
</shape>
I hope this will help you