前言: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. android 博客列表

    1.  Hongyang http://blog.csdn.net/lmj623565791/article/details/37970961

  2. 个人或者企业怎么进行app开发?开发一款APP应用大概须要多少钱?

    App开发.是指专注于手机应用软件开发与服务. App是application的缩写,通常专指手机上的应用软件,或称手机client.另外眼下有非常多在线app开发平台.当然移动互联网时代是全民的移动 ...

  3. 图解avaScript中this指向(超透彻)

    一个图讲清楚JavaScript中this指向: 说明: (1)严格模式下,禁止this关键字指向全局对象会报错. (2)闭包中的this对象具有全局性,因此通常指向window.  (3)优先级:n ...

  4. 【设计模式 7】从公司的目前框架和API Gateway,谈谈对外观模式的理解

    我,第一次用到外观模式,应该是3年多以前.那时候是做一个收费系统,在当时的U层和B层之间,加了一层Facade.当时,在一些复杂的业务逻辑处理时,感受到了加入外观层的好处,但对于一些简单的(我指的是, ...

  5. Mac+docker+flask

    1.先要保证mac电脑安装docker 安装的话可以通过命令brew install docker 安装成功后启动,docker 然后在终端执行docker version 或者docker info ...

  6. 开放平台(接口)开发-1-天气API接口大全

     前几天有个公司让准备一下第二次面试.应聘的是IOS开发实习生,可是之前一直做android,IOS刚接触了一个月,会的不是非常多,所以决定做一个实际的项目展现给面试官,余同学给了个建议:能够做一 ...

  7. jQuery select的操作实现代码

          //改变时的事件  $("#testSelect").change(function(){ //事件发生生 jQuery('option:selected', this ...

  8. Sublime text 3 搭建Python3 IDE

    起因:为了提高编码工作中的体验,Sublime Text:不仅具有华丽的界面,还支持插件扩展机制,用她来写代码,绝对是一种享受. Vim难于上手,Eclipse,VS 体积庞大,即便体积轻巧迅速启动的 ...

  9. 在训练CNN时,loss稳定在log(类别数)

    参见知乎问题! https://www.zhihu.com/question/275774218 很多框架都会有一个问题,当卷积 weight NaN 之后,卷积的 output 会变成 NaN.然后 ...

  10. Linux如何关机与关机命令祥解

    Linux关机命令祥解 1.直接关电源 2.init 0 3.telinit 0 4.shutdown -h now 5.halt6.poweroff 1.shutdown shutdown命令安全地 ...