答案 0 :(得分:0)
在styles.xml
<!-- TabTextSizeAppearance to define your tab text size -->
<style name="TabTextSizeAppearance" parent="TextAppearance.AppCompat.Caption">
<item name="android:textSize">14sp</item>
<item name="android:textStyle">normal</item>
</style>
<!-- MyTabLayout to define TabLayout parameters -->
<style name="MyTabLayout" parent="Widget.Design.TabLayout">
<item name="tabGravity">fill</item>
<item name="tabMode">fixed</item>
<item name="tabPaddingStart">4dp</item>
<item name="tabPaddingEnd">4dp</item>
<item name="tabSelectedTextColor">@color/black</item>
<item name="tabTextAppearance">@style/TabTextSizeAppearance</item>
</style>
最后,将其添加到您的dimens.xml
<dimen name="design_tab_text_size_2line" tools:ignore="PrivateResource">14sp</dimen>
此dimen
的大小应与TabTextSizeAppearance
的文本大小相同,以确保即使长文本也可以保持相同的大小
然后在您的xml中使用它
<android.support.design.widget.TabLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
style="@style/MyTabLayout"
>
<android.support.design.widget.TabItem
...
</android.support.design.widget.TabLayout>