52.Android中TabLayout修改字体大小

场景

在使用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">

效果对比

修改样式前
修改样式后
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。