android tab 自定义样式,TabLayout之自定义样式

本文详细介绍了如何自定义TabLayout的样式,包括Tab的文本样式、图标显示、Indicator长度调整,并展示了与ViewPager的联动使用。还讨论了如何处理Tab的点击事件和自定义TabItem,提供了解决Tab不显示文本问题的方法。
摘要由CSDN通过智能技术生成

本篇主要介绍TabLayout在开发中一些常见的用法,不习惯简书代码风格的,也可以在 Android_Note查看.

TabLayout的默认样式:

app:theme="@style/Widget.Design.TabLayout"

从系统定义的该样式继续深入:

fill

fixed

264dp

?attr/colorAccent

2dp

12dp

12dp

?attr/selectableItemBackground

@style/TextAppearance.Design.Tab

?android:textColorPrimary

接着,看看系统定义Tab文本的样式(注意textAllcaps这个属性):

14dp

?android:textColorSecondary

true

从系统定义TabLayout的默认样式可以看出,我们可以改变TabLayout对应的系统样式的属性值来适配我们自己的需求.

TabLayout的基本用法

TabLayout独立使用使用时,可以xml布局中静态添加tab个数及其样式,也可以动态添加Tab的个数及其样式,如:

android:id="@+id/tablayout"

android:background="@color/colorPrimary"

android:layout_width="match_parent"

android:layout_height="wrap_content">

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:text="Android"/>

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:icon="@mipmap/ic_launcher"/>

ed129686f2cc

这里写图片描述

或者:

android:id="@+id/tablayout"

android:background="@color/colorPrimary"

android:layout_width="match_parent"

android:layout_height="wrap_content"/>

private int[] images = new int[]{

R.drawable.ic_account_balance_wallet_black,

R.drawable.ic_android_black,

R.drawable.ic_account_box_black};

private String[] tabs = new String[]{"小说", "电影", "相声"};

TabLayout tabLayout = (TabLayout) findViewById(R.id.tablayout);

tabLayout.addTab(tab

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值