The tabs in the ActionBar
use a different theme than the tabs in TabHost
.
All you need to do is change android:actionBarTabStyle
to android:tabWidgetStyle
.
Full example
<style name="Your.Theme" parent="@android:style/Theme.Holo.Light.DarkActionBar">
<item name="android:tabWidgetStyle">@style/Your.TabWidget</item>
</style>
<style name="Your.TabWidget" parent="@android:style/Widget.Holo.TabWidget">
<item name="*android:tabLayout">@layout/your_tab_layout</item>
</style>
<style name="Your.Tab" parent="@android:style/Widget.Holo.ActionBar.TabView">
<item name="android:background">@drawable/your_tab_indicator</item>
<item name="android:layout_width">0dip</item>
<item name="android:layout_weight">1</item>
<item name="android:minWidth">80dip</item>
</style>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
style="@style/Your.Tab"
android:layout_height="?android:attr/actionBarSize"
android:orientation="horizontal" >
<ImageView
android:id="@android:id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:visibility="gone" />
<TextView
android:id="@android:id/title"
style="@android:style/Widget.Holo.ActionBar.TabText"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:maxWidth="180dip" />
</LinearLayout>
Although, android:tabLayout
isn't a public attribute (hence the *). Google wouldn't recommend creating the style like that because of this and instead would suggest modifying the indicator dynamically. So, something like this:
final TabWidget tabWidget = tabHost.getTabWidget();
for (int i = 0; i < tabWidget.getTabCount(); i++) {
final View tab = tabWidget.getChildTabViewAt(i);
tab.setBackground(getResources().getDrawable(R.drawable.your_tab_indicator));
}
Results