Android-ViewPagerIndicator框架使用——TabPageIndicator
前言:TabPageIndicator这个类和之前的不大一样,他不仅提供了展示的功能,而且可以点击,下面的viewpager可以跳转的有点tabhost的感觉。
一:布局文件的定义,simple_tabs,其中的TabPageIndicator可以放在viewpager的上面或是下面都行,效果还行吧。
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" > <com.viewpagerindicator.TabPageIndicator
android:id="@+id/indicator"
android:layout_width="fill_parent"
android:layout_height="wrap_content" /> <android.support.v4.view.ViewPager
android:id="@+id/pager"
android:layout_width="fill_parent"
android:layout_height="0dp"
android:layout_weight="1" />
</LinearLayout>
二:在代码中使用:
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.simple_tabs); FragmentPagerAdapter adapter= new GoogleMusicAdapter(
getSupportFragmentManager()); ViewPager pager = (ViewPager) findViewById(R.id.pager);
pager.setAdapter(adapter); TabPageIndicator indicator = (TabPageIndicator) findViewById(R.id.indicator);
indicator.setViewPager(pager);
}
其中的adapter需要注意,因为标识的标签文字需要在adapter中添加:
/**
* 标题
*/
private static final String[] CONTENT = new String[] { "Recent", "Artists",
"Albums", "Songs", "Playlists", "Genres" };
"Albums", "Songs", "Playlists", "Genres" };
/**
* 继承PagerAdapter或PagerAdapter子类的时候需要实现这个方法,用于设置标题
*/
@Override
public CharSequence getPageTitle(int position) {
return CONTENT[position % CONTENT.length].toUpperCase();
}
若想让标签带一张图片,在定义adatper的时候,还需要实现IconPagerAdapter接口,并实现其中的getIconResId方法:
private static final int[] ICONS = new int[] {
R.drawable.perm_group_calendar, R.drawable.perm_group_camera,
R.drawable.perm_group_device_alarms,
R.drawable.perm_group_location, };
/**
* 返回标签的图片
*/
@Override
public int getIconResId(int index) {
return ICONS[index];
}
三:修改样式,下面是比较重要的属性:
<!-- 点击时在不同状态下显示的背景色 -->
<item name="android:background">@drawable/custom_tab_indicator</item>
<!-- 分割线图片设置 -->
<item name="android:divider">@drawable/custom_tab_indicator_divider</item>
<!-- 设置分割线的显示位置,或是不显示 -->
<item name="android:showDividers">none</item>
四:使用方法这个使用时候比较特别,貌似只能用主题来设置:
1.设置主题,必须按照一下三步设置,其中的StyledIndicators这名字可以自定义:
<!-- 第一步设置主题 -->
<style name="StyledIndicators" parent="@android:style/Theme.Light">
<item name="vpiTabPageIndicatorStyle">@style/CustomTabPageIndicator</item>
</style>
<!-- 第二步设置主题 -->
<style name="CustomTabPageIndicator" parent="Widget.TabPageIndicator"> <!-- 点击时在不同状态下显示的背景色 -->
<item name="android:background">@drawable/custom_tab_indicator</item>
<!-- 分割线图片设置 -->
<item name="android:divider">@drawable/custom_tab_indicator_divider</item>
<!-- 设置分割线的显示位置,或是不显示 -->
<item name="android:showDividers">none</item> <item name="android:textAppearance">@style/CustomTabPageIndicator.Text</item>
<item name="android:textColor">#FF555555</item>
<item name="android:textSize">16sp</item>
<item name="android:dividerPadding">10dp</item>
<item name="android:paddingLeft">8dp</item>
<item name="android:paddingRight">8dp</item>
<item name="android:fadingEdgeLength">10dp</item>
<item name="android:fadingEdge">horizontal</item>
</style>
<!-- 第三步设置主题 -->
<style name="CustomTabPageIndicator.Text" parent="android:TextAppearance.Medium">
<item name="android:typeface">monospace</item>
</style>
2.使用主题:
<activity
android:name=".SampleTabsStyled"
android:label="Tabs/Styled"
android:theme="@style/StyledIndicators" >
<intent-filter>
<action android:name="android.intent.action.MAIN" /> <category android:name="com.jakewharton.android.viewpagerindicator.sample.SAMPLE" />
</intent-filter>
</activity>
源码以及Demo下载地址:http://download.csdn.net/detail/as294985925/6796117
Android-ViewPagerIndicator框架使用——TabPageIndicator的更多相关文章
- Android开源框架ViewPagerIndicator的基本使用
转载本博客请注明出处:点击打开链接 http://blog.csdn.net/qq_32059827/article/details/52495647 很多新闻资讯类的app都有一些共性,那就是 ...
- Android-ViewPagerIndicator框架使用——TabPageIndicator以及样式的修改
今天介绍一个常用的框架,一般app都会用到这样的框架,下面就来介绍框架的使用以及样式的修改,那就以我自己写的例子来向大家介绍吧! 首先给出xml ,在相应窗口的布局文件中引入TabPageIndica ...
- Android开源框架ViewPageIndicator和ViewPager实现Tab导航
前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...
- Android百大框架排行榜
Android百大框架排行榜 15类Android通用流行框架 - 流风,飘然的风 - 博客园https://www.cnblogs.com/zdz8207/p/android-opensource- ...
- 2017年Android百大框架排行榜
框架:提供一定能力的小段程序 >随意转载,标注作者"金诚"即可 >本文已授权微信公众号:鸿洋(hongyangAndroid)原创首发. >本文已经开源到Gith ...
- android 优秀框架整理
程序员界有个神奇的网站,那就是github,这个网站集合了一大批优秀的开源框架,极大地节省了开发者开发的时间,在这里我进行了一下整理,这样可以使我们在使用到时快速的查找到,希望对大家有所帮助! 1. ...
- 2017年Android百大框架排行榜(转)
一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由.网络层.UI层.通信层或其他单一功能的框架 混合开发框架:提供开发hybrid app.h5与webview结合能力.web app能力的框架 ...
- Android 开源框架Universal-Image-Loader学习
Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二)--- 图片 ...
- Android 数据库框架OrmLite的使用(一)
在这里记录下最基本的用法,官网上可了解相关的介绍. 1.下载OrmLite jar 在下载android的:ormlite-android-4.48.jar和ormlite-core-4.48.jar ...
随机推荐
- jquery的confirm插件介绍
参考:1.http://craftpip.github.io/jquery-confirm/ 2.http://www.bootcdn.cn/jquery-confirm/readme/ 3.h ...
- http://blog.163.com/eugeneheen_chen@126/blog/static/120812157201291994916866/
http://blog.163.com/eugeneheen_chen@126/blog/static/120812157201291994916866/
- IBM AppScan安全測试一例——已解密的登录请求
问题严重级别:高 此类问题在做政府项目(第三方软件评測中心)验收的时,须要马上整改.例如以下图:
- 【Hadoop】伪分布式环境搭建、验证
Hadoop伪分布式环境搭建: 自动部署脚本: #!/bin/bash set -eux export APP_PATH=/opt/applications export APP_NAME=Ares ...
- Python 获取图片文件大小并转换为base64编码
import os import base64 fileSize = os.path.getsize(文件路径) with open(文件路径, 'rb') as f: data = base64.b ...
- Java 9的14个新特性总结
Java 9 包含了丰富的特性集.虽然Java 9没有新的语言概念,但是有开发者感兴趣的新的API和诊断命令. 我们将快速的,着重的浏览其中的几个新特性: 模块化系统–Jigsaw 项目 模块化是一 ...
- web.xml文件中配置mime下载文件类型(转)
转自:http://5aijava.iteye.com/blog/166600 TOMCAT在默认情况下下载.rar的文件是把文件当作text打开,以至于IE打开RAR文件为乱码,如果遇到这种情况时不 ...
- 【FAQ】Ubuntu环境下ant编译android代码问题
在Ubuntu14.04环境下,编译android程序时候,运行ant debug的时候出现如下异常:
- hdu1698 Just a Hook (线段树区间更新 懒惰标记)
Just a Hook Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Tota ...
- 《Mining the Web:Transforming Customer Data into Customer Value》读后札记
<Mining the Web:Transforming Customer Data into Customer Value> <Web数据挖掘:将客户数据转化为客户价值> — ...