As mentioned in mbaird, the best solution is to use a background with a selector, so you don't need to check onTabChanged and perform a manual update. The minimum code is here:
private void initTabsAppearance(TabWidget tabWidget) {
Where tab_bg is the xml that can be selected using the selector:
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:state_selected="true" android:drawable="@drawable/tab_bg_selected" /> <item android:drawable="@drawable/tab_bg_normal" /> </selector>
To fully customize the tab, I will add code to change the style of the tab text using a custom theme. Add this to styles.xml :
<resources> <style name="MyCustomTheme" parent="@android:style/Theme.Light.NoTitleBar"> <item name="android:tabWidgetStyle">@style/CustomTabWidget</item> </style> <style name="CustomTabWidget" parent="@android:style/Widget.TabWidget"> <item name="android:textAppearance">@style/CustomTabWidgetText</item> </style> <style name="CustomTabWidgetText" parent="@android:style/TextAppearance.Widget.TabWidget"> <item name="android:textSize">12sp</item> <item name="android:textStyle">bold</item> </style> </resources>
To use this theme, define it in AndroidManifest.xml:
<application android:theme="@style/MyCustomTheme">
And now you have tab widgets with a custom background and custom text style .
peter.bartos Sep 17 '11 at 9:13 2011-09-17 09:13
source share