<android.support.design.widget.TabLayout
android:id="@+id/tabLayout"
android:layout_width="match_parent"
android:layout_height="50dp"
app:tabIndicatorColor="@color/zitilan"
app:tabIndicatorHeight="5dp"
app:tabMode="fixed"
app:tabPaddingEnd="-1dp"
app:tabPaddingStart="-1dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
app:tabTextAppearance="@style/MyCustomTextAppearance"
app:tabTextColor="@color/zitihui"></android.support.design.widget.TabLayout>
tabLayout = (TabLayout) findViewById(R.id.tabLayout);
String[] tabs = new String[]{"全部", "待发货", "已发货", "待付款", "退款", "交易成功"};
for (int i = 0; i < tabs.length; i++) {
tabLayout.addTab(tabLayout.newTab().setText(tabs[i]));
}
<style name="MyCustomTextAppearance" parent="TextAppearance.Design.Tab">
<item name="textAllCaps">true</item>
<item name="android:textAllCaps">true</item>
<item name="android:textSize">14sp</item>
</style>

重点:使用tabpading 清除tab的内间距,避免因为固定内间距导致长的文字被压缩
|