1. style.xml
<style name="TextBaseStyle">
<item name="android:layout_width">wrap_content</item>
<item name="android:layout_height">wrap_content</item>
<item name="android:textSize">18sp</item>
<item name="android:textColor">@color/black</item>
</style>
<style name="TabBaseStyle" parent="TextBaseStyle">
<item name="android:layout_width">0dp</item>
<item name="android:layout_height">match_parent</item>
<item name="android:layout_weight">1</item>
<item name="android:gravity">center</item>
<item name="android:button">@null</item>
<item name="android:background">@drawable/tab_bg_selector</item>
<item name="android:textColor">@color/tab_text_selector</item>
</style>
2. 自定义文字和背景selector
<!--tab_text_selector.xml-->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:color="@color/white"/>
<item android:state_checked="false" android:color="@color/black"/>
</selector>
<!--tab_bg_selector.xml-->
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_checked="true" android:drawable="@color/colorPrimary"/>
<item android:state_checked="false" android:drawable="@color/white"/>
</selector>
来源:oschina
链接:https://my.oschina.net/yuewawa/blog/4287071