转载自: https://blog.csdn.net/u013184970/article/details/115527627
解决TabLayout或MaterilToolBar设置字体大小不起作用的问题
TabLay
<android.support.design.widget.TabLayout
android:id="@+id/tab_type"
style="@style/MyBgTablayoutstyle"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/white"
app:tabTextAppearance="@style/tabLayout_testStyle"
app:tabMode="scrollable" />
注意:一定要在app:tabTextAppearance="@style/tabLayout_testStyle"里设置,一定要继承TextAppearance.Design.Tab才可以;在style="@style/MyBgTablayoutstyle"里设置的文字大小不起作用。
<style name="tabLayout_testStyle" parent="TextAppearance.Design.Tab">
<!--此处可用dp也可以用sp都可以,任选一个-->
<item name="android:textSize">12sp</item>
</style>
<style name="MyBgTablayoutstyle" parent="Base.Widget.Design.TabLayout">
<item name="tabBackground">@drawable/bg_blue_corner_tab</item>
<item name="tabIndicatorColor">@color/transparent</item>
<item name="tabIndicatorHeight">0dp</item>
<item name="tabSelectedTextColor">@color/text</item>
<item name="android:textSize">12sp</item>
<item name="android:textColor">@color/gray_7C</item>
</style>
MaterilToolBar同理
<com.google.android.material.appbar.MaterialToolbar
android:fitsSystemWindows="true"
android:id="@+id/toolbar_fragments_in_navhost"
style="@style/Widget.Shrine.Toolbar"
android:layout_width="match_parent"
android:layout_height="82dp"
android:background="@drawable/bgcolor_toolbar_and_bottom"
android:paddingStart="12dp"
android:paddingLeft="12dp"
android:paddingEnd="12dp"
android:paddingRight="12dp"
app:contentInsetStart="0dp"
app:layout_scrollFlags="scroll"
app:titleTextColor="@color/cardview_dark_background"
app:titleTextAppearance="@style/toolbar_testStyle"
app:navigationIcon="@drawable/ic_toolbar_menu"
app:title="发现"
app:titleCentered="true" />