viewpagerindicator的取代品之一TabLayout(谷歌官方控件)
来源:互联网 发布:淘宝店铺可以复制么 编辑:程序博客网 时间:2024/06/03 21:27
viewpagerindicator的取代品之一TabLayout(谷歌官方控件)
首先展示一下,代码成功之后大概的效果(我承认很丑!).
本人使用的为Android Studio
首先在build.gradle中添加compile 'com.android.support:design:22.2.0'
后面的这个版本号可能需要修改一下.
比如我的程序targetSdkversion是23的就会出现下面的错误.
解决办法,如下图
完成之后,会在build.gradle中看到 compile 'com.android.support:design:xx.xx.xx'已添加
开始使用
布局文件
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="http://schemas.android.com/apk/res-auto" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:orientation="vertical" android:layout_height="match_parent" tools:context=".MainActivity"> <android.support.design.widget.TabLayout android:id="@+id/tab" android:layout_width="match_parent" app:tabIndicatorColor="#FF00FF00" app:tabSelectedTextColor="#FFFFFF00" app:tabTextColor="#FFFF0000" android:layout_height="wrap_content"/> <android.support.v4.view.ViewPager android:id="@+id/vp" android:layout_width="fill_parent" android:layout_height="0dp" android:layout_weight="1" /> </LinearLayout>
其中 app:tabIndicatorColor="#FF00FF00" // 下方下划线颜色
app:tabSelectedTextColor="#FFFFFF00" // 被选中后,文字的颜色
app:tabTextColor="#FFFF0000" // 默认的文本颜色
运行一下就明白.
程序中的关键代码
- tabLayout.setTabMode(TabLayout.MODE_SCROLLABLE);//用来设置tab宽度超出屏幕时的解决办法,这里设置为可滑动.
viewPager.setAdapter();//不会这个请另行搜索
值得注意的是,在重写viewPager适配器的时候,要重写
@Override public CharSequence getPageTitle(int position) { return strs[position]; }
tabLayout.setupWithViewPager(viewPager);//一定将这句话放到viewpager设置适配器的后面.
大功告成!
1 0
- viewpagerindicator的取代品之一TabLayout(谷歌官方控件)
- 使用TabLayout代替ViewPagerIndicator
- 原生TabLayout实现ViewPagerIndicator
- 使用TabLayout代替ViewPagerIndicator
- TabLayout替换ViewPagerIndicator
- 自定义简单的ViewPagerIndicator控件
- 自定义控件ViewPagerIndicator的使用
- 最新的TabLayout实现tab功能代替viewPagerIndicator。
- TabLayout代替PagerSlidingTabScrip or viewpagerIndicator
- 开源控件ViewPagerIndicator的使用
- 开源控件ViewPagerIndicator的使用
- 开源控件ViewPagerIndicator的使用
- 开源控件ViewPagerIndicator的使用
- 谷歌官方的下拉刷新控件
- Android--TabLayout控件的使用
- TabLayout控件的简单使用
- 自定义控件-ViewPagerIndicator
- 自定义控件之-ViewPagerIndicator
- GIS+=地理信息+大数据——纽约出租车大数据下载
- Python爬取一个网页的图片
- 转移Window Xp Mode
- Beginning Python Chapter9
- Java简介
- viewpagerindicator的取代品之一TabLayout(谷歌官方控件)
- High Performance MySQL Chapter2
- 理解C语言——从小菜到大神的晋级之路(8)——数组、指针和字符串
- migrate遇到err mongoid[not found]
- 数据字典构件
- [转]Java 获取操作系统的信息
- 百思学习笔记01-基本配置
- uva1210
- 二维码--用java生成二维码(来自网易云课堂)