前言: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的更多相关文章

  1. Android开源框架ViewPagerIndicator的基本使用

    转载本博客请注明出处:点击打开链接    http://blog.csdn.net/qq_32059827/article/details/52495647 很多新闻资讯类的app都有一些共性,那就是 ...

  2. Android-ViewPagerIndicator框架使用——TabPageIndicator以及样式的修改

    今天介绍一个常用的框架,一般app都会用到这样的框架,下面就来介绍框架的使用以及样式的修改,那就以我自己写的例子来向大家介绍吧! 首先给出xml ,在相应窗口的布局文件中引入TabPageIndica ...

  3. Android开源框架ViewPageIndicator和ViewPager实现Tab导航

    前言: 关于使用ViewPageIndicator和ViewPager实现Tab导航,在开发社区里已经有一堆的博客对其进行了介绍,假设我还在这里写怎样去实现.那简直就是老生常谈,毫无新奇感,并且.我也 ...

  4. Android百大框架排行榜

    Android百大框架排行榜 15类Android通用流行框架 - 流风,飘然的风 - 博客园https://www.cnblogs.com/zdz8207/p/android-opensource- ...

  5. 2017年Android百大框架排行榜

    框架:提供一定能力的小段程序 >随意转载,标注作者"金诚"即可 >本文已授权微信公众号:鸿洋(hongyangAndroid)原创首发. >本文已经开源到Gith ...

  6. android 优秀框架整理

    程序员界有个神奇的网站,那就是github,这个网站集合了一大批优秀的开源框架,极大地节省了开发者开发的时间,在这里我进行了一下整理,这样可以使我们在使用到时快速的查找到,希望对大家有所帮助! 1. ...

  7. 2017年Android百大框架排行榜(转)

    一.榜单介绍 排行榜包括四大类: 单一框架:仅提供路由.网络层.UI层.通信层或其他单一功能的框架 混合开发框架:提供开发hybrid app.h5与webview结合能力.web app能力的框架 ...

  8. Android 开源框架Universal-Image-Loader学习

    Android 开源框架Universal-Image-Loader完全解析(一)--- 基本介绍及使用 Android 开源框架Universal-Image-Loader完全解析(二)--- 图片 ...

  9. Android 数据库框架OrmLite的使用(一)

    在这里记录下最基本的用法,官网上可了解相关的介绍. 1.下载OrmLite jar 在下载android的:ormlite-android-4.48.jar和ormlite-core-4.48.jar ...

随机推荐

  1. Spring(八)编码剖析@Resource注解的实现原理

    配置文件beans2.xml <?xml version="1.0" encoding="UTF-8"? > <beans xmlns=&qu ...

  2. Laravel 5 系列教程三:视图变量传递和Blade

    免费视频教程地址https://laravist.com/series/laravel-5-basic 上一篇我们简单地说了Router,Views和Controllers的工作流程,这一次我就按照上 ...

  3. [Android] 给图像加入相框、圆形圆角显示图片、图像合成知识

        前一篇文章讲述了Android触屏setOnTouchListener实现突破缩放.移动.绘制和加入水印,继续我的"随手拍"项目完毕给图片加入相框.圆形圆角显示图片和图像合 ...

  4. 网络编程基础——学习阻塞,非阻塞(select和epoll)

    <h3 class="xyn" helvetica="" neue',="" helvetica,="" aria ...

  5. 攻克了Cocoapods Undefined symbols for architecture _OBJC_CLASS_xxxx的问题,辛苦死我了,记录下之后有空在研究

    网上找了一大包将尽3个小时没有解决,原本以为是我升级到10.10的原因,把cocoapod 重装 stackoverflow google 用尽了也不知道为啥 结果是这个样子的 编译出现这个.... ...

  6. Visual studio C++ MFC的库函数末尾添加“A”和“W”的意义

    背景 在使用Visual studio C++ MFC库函数ModifyMenu(...)函数,在Visual studio自动代码补全里提示没有ModifyMenu(...)这个函数,倒是有Modi ...

  7. 图片扩展---基于opencv-python实现

    目标: 将一张长方形图片扩展成一张正方形图片,例如: 200x300x3的一张图片扩展成一张300x300x3的图片,填充部分使用白色. 代码: import cv2 import os imglis ...

  8. 通过WSDL命令,将WSDL生成代理类

    VS2010 打开命令行窗口(开始-VS2010--Visual Studio Tools--Visual Studio Command Prompt) 输入: wsdl  /l:cs /n:newN ...

  9. atitit.线程死锁 卡住无反应 的原因in cmd调用的解决方案  v3 q39

    atitit.线程死锁 卡住无反应 的原因in cmd调用的解决方案  v3 q39 1. 问题::线程死锁  卡住无反应1 1.1. 分类:: cmd调用,  net io  , file  io  ...

  10. Atitit.收银系统pos 以及打印功能的行业标准

    Atitit.收银系统pos 以及打印功能的行业标准 1. ESC指令序列 Escape指令序列不同于ESC/POS指令 1 2. 打印标准OPOS POSPrinter 与 CashDrawer 驱 ...