52.Android中TabLayout修改字体大小

2019-08-06  本文已影响0人  TensorFlow开发者

场景

在使用TabLayout + ViewPager+Fragment组合时,有时候标签tab文字大小、文字样式不符合自己项目的需求。但TabLayout控件没有直接属性修改文字大小、加粗等。有办法修改,只是稍微有点麻烦而已,在此记录一下。

<android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        app:tabIndicatorHeight="0dp"
        app:tabSelectedTextColor="#00f"
        app:tabTextColor="#000">

解决方案

需要使用样式为该属性赋值:app:tabTextAppearance="@style/wallet_third_tab_layout"
wallet_third_tab_layout是在res---values---styles.xml中添加的自定义样式。

<style name="wallet_third_tab_layout">
        <item name="android:textSize">14dp</item>
        <item name="android:textStyle">bold</item>
    </style>

如下所示:

<android.support.design.widget.TabLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:tabMode="scrollable"
        app:tabIndicatorHeight="0dp"
        app:tabSelectedTextColor="#00f"
        app:tabTextColor="#000"
        app:tabTextAppearance="@style/wallet_third_tab_layout">

效果对比

修改样式前 修改样式后
上一篇 下一篇

猜你喜欢

热点阅读