android tab传递数据,Android中TabLayout结合ViewPager实现页面切换

本文详细介绍了如何在Android中使用TabLayout结合ViewPager实现页面切换,包括添加依赖、XML布局、创建Adapter、设置数据以及完善Fragment,提供了一个完整的实现流程。
摘要由CSDN通过智能技术生成

一、实现思路

1、在build.gradle中添加依赖,例如:

compile 'com.android.support:support-v4:23.4.0'

compile 'com.android.support:design:23.4.0'

也可以将support-v4替换为appcompat-v7,例如:

compile 'com.android.support:appcompat-v7:23.4.0'

因为appcompat-v7是依赖于support-v4的。

更多说明可参考官方文档support library部分。

2、在xml中添加TabLayout和ViewPager,例如:

xmlns:tool="http://schemas.android.com/tools"

xmlns:app="http://schemas.android.com/apk/res-auto"

tool:context=".TabViewActivity"

android:orientation="vertical"

android:layout_width="match_parent"

android:layout_height="match_parent">

android:id="@+id/tab_layout"

android:layout_width="match_parent"

android:layout_height="wrap_content"

android:background="@color/tabLayoutBackground"

app:tabMode="scrollable"

app:tabTextColor="@color/color_white"

app:tabSelectedTextColor="@color/tabSelectedText"

app:tabIndicatorHeight="3dp"

app:tabIndicatorColor="@color/color_white"/>

android:id="@+id/view_pager"

android:layout_width=

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值