Android-TabLayout设置内容宽度以及下划线宽度

本文介绍如何通过设置TabLayout和ViewPager的样式属性来调整其显示效果,包括改变间距、下划线及文字大小等。
默认图:


效果图:


  
项目中使用到需要像今日头条那种实现顶部横向滑动标题功能,本人项目中使用TabLayout+ViewPager实现,

但是,实现后默认的TabLayout间距特别大,并且下划线,文字大小等很难实现,百度查阅了好多资料,并不好使,
最后才发现,其实特别简单,只是细节而已:
  1.设置TabLayout中各个条目之间的间距,利用app:tabPaddingEnd="10dp"和app:tabPaddingStart="10dp"即可实现,
但是,在实际显示中,并没有起作用,所以需要设置额外的属性app:tabGravity="fill",app:tabMinWidth="30dp"
  2、设置字体大小,需要在style中自定义tabTextAppearance属性TabLayoutTextStyle,具体如下

 

在xml中

         <android.support.design.widget.TabLayout
                    android:layout_width="match_parent"
                    android:layout_height="40dp"
                    app:tabGravity="fill"
                    app:tabIndicatorColor="@color/Red"
                    app:tabMinWidth="30dp"
                    app:tabMode="scrollable"
                    app:tabPaddingEnd="10dp"
                    app:tabPaddingStart="10dp"
                    app:tabTextAppearance="@style/TabLayoutTextStyle"     
        />

style中

<style name="TabLayoutTextStyle" parent="TextAppearance.AppCompat.Widget.ActionBar.Title">
        <item name="android:textSize">16sp</item>
    </style>

 

转载于:https://www.cnblogs.com/shen-hua/p/7264029.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值