美文网首页
52.Android中TabLayout修改字体大小

52.Android中TabLayout修改字体大小

作者: TensorFlow开发者 | 来源:发表于2019-08-06 16:18 被阅读0次

场景

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

效果对比

修改样式前 修改样式后

相关文章

网友评论

      本文标题:52.Android中TabLayout修改字体大小

      本文链接:https://www.haomeiwen.com/subject/hhlwdctx.html