Android开发之简单修改TabLayout默认文字大小的方法(亲测可用)

论坛 期权论坛 编程之家     
选择匿名的用户   2021-6-2 16:40   1332   0

很简单,先看图:

这是比较小的12sp

我们看下大字体28sp的

实际上很简单,给TabLayout设置一个style即可

划重点!style一定要继承TextAppearance.Design.Tab才可以成功

 <style name="tabLayout_style" parent="TextAppearance.Design.Tab">
        <!--此处可用dp也可以用sp都可以,任选一个-->
        <item name="android:textSize">28sp</item>
        <item name="android:textSize">12dp</item>
    </style>

怎么用呢?看代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/common_title_view" />

    <android.support.design.widget.TabLayout
        android:id="@+id/tl_coupon"
        android:layout_width="match_parent"
        android:layout_height="@dimen/dp_44"
        android:background="@color/white"
        app:tabIndicatorColor="@color/colorMain"
        app:tabIndicatorHeight="@dimen/dp_1"
        app:tabSelectedTextColor="@color/colorMain"
        app:tabTextAppearance="@style/tabLayout_style"
        app:tabTextColor="@color/black" />
</LinearLayout>

就可以了。

分享到 :
0 人收藏
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

积分:3875789
帖子:775174
精华:0
期权论坛 期权论坛
发布
内容

下载期权论坛手机APP