原创:转载请标明出处:
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"

最后上一张效果图:

更多相关文章

  1. Android获取服务器后台数据
  2. Android(第三种动画)属性动画完全解析(上),初识属性动画的基本用法
  3. 【Android(安卓)开发】:UI控件之 ProgressBar 进度条的使用
  4. Android(安卓)复习巩固------ Animation 动画 (简介)
  5. Android(安卓)focus search returned a view that wasn't able t
  6. android中selector改变界面状态用法小结
  7. android TextView 改变边框
  8. android 10.0版本合入GMS包
  9. android Configuration系统设置

随机推荐

  1. android:largeHeap属性
  2. Android动画开发——Animation动画效果 .
  3. Android 使用View类绘图
  4. 更好用的Android Toast
  5. android 地图 infoWindow的每个控件添加
  6. android studio 添加Butterknife 插件
  7. android摄像头调用资料收集
  8. android语音识别 android.speech 包分析
  9. 如何让Android字体自适应屏幕分辨率
  10. 刚刚注册了一个android两天的培训