Android中TabLayout切换选项背景和修改字体大小
16lz
2021-01-26
原创:转载请标明出处:
http://blog.csdn.net/ming2316780/article/details/51763864
本文出自:【Android_Jerry的博客】
TabLayout切换选项背景和修改字体大小
首先呢,TabLayout是Android5.0后出的新控件,使用需要导入design包,一般情况下,TabLayout需要和ViewPager搭配使用。
在TabLayout标签属性中,只有改变切换文字颜色属性的,就连文字大小的设置也没有直接属性可设置。
其实设置很简单,只需要设置 app:tabBackground 和 app:tabTextAppearance 的属性,即可实现。
TabLayout xml设置代码如下:
"@+id/tablayout_video" android:layout_width="match_parent" android:layout_height="@dimen/tablayout_height" app:tabBackground="@drawable/tablayout_background" app:tabIndicatorHeight="0dp" app:tabSelectedTextColor="@color/white" app:tabTextAppearance="@style/TabLayoutTextStyle" app:tabTextColor="@color/white" />
app:tabBackground 属性:此处要写一个selector
<selector xmlns:android="http://schemas.android.com/apk/res/android"> <item android:drawable="@drawable/tab_horizontal_item_p" android:state_selected="true" /> <item android:drawable="@drawable/tab_horizontal_item_d" />selector>
(tab_horizontal_item_d) (tab_horizontal_item_p)
app:tabTextAppearance 属性:此处要写一个style
<style name="TabLayoutTextStyle"> <item name="android:textSize">@dimen/text_16_spstyle>
最后说一下,因为TabLayout在布局底部是自带一条滚动条的,为了实现块状切换的效果,可以把 app:tabIndicatorHeight 属性设置为0dp,去掉滚动条
app:tabIndicatorHeight="0dp"
最后上一张效果图:
更多相关文章
- Android获取服务器后台数据
- Android(第三种动画)属性动画完全解析(上),初识属性动画的基本用法
- 【Android(安卓)开发】:UI控件之 ProgressBar 进度条的使用
- Android(安卓)复习巩固------ Animation 动画 (简介)
- Android(安卓)focus search returned a view that wasn't able t
- android中selector改变界面状态用法小结
- android TextView 改变边框
- android 10.0版本合入GMS包
- android Configuration系统设置