Android滑动页面导航效果: PagerSlidingTabStrip

来源:互联网 发布:知客是什么意思 编辑:程序博客网 时间:2024/05/17 00:33

把github上的PagerSlidingTabStrip稍作修改:

tab的文字颜色选中变色(原版文字不变色),类似微信导航


栗子:http://download.csdn.net/detail/onlyonecoder/7722021


PagerSlidingTabStrip 自定义属性列表:

  • pstsIndicatorColor Color of the sliding indicator
  • pstsUnderlineColor Color of the full-width line on the bottom of the view
  • pstsDividerColor Color of the dividers between tabs
  • pstsIndicatorHeightHeight of the sliding indicator
  • pstsUnderlineHeight Height of the full-width line on the bottom of the view
  • pstsDividerPadding Top and bottom padding of the dividers
  • pstsTabPaddingLeftRight Left and right padding of each tab
  • pstsScrollOffset Scroll offset of the selected tab
  • pstsTabBackground Background drawable of each tab, should be a StateListDrawable
  • pstsShouldExpand If set to true, each tab is given the same weight, default false
  • pstsTextAllCaps If true, all tab titles will be upper case, default true
修改后加了一个属性 selectedTabTextColor

如果不设置 默认和 滑动指示器颜色(pstsIndicatorColor)一致


下图效果的代码:


[html] view plaincopy在CODE上查看代码片派生到我的代码片
  1. <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"  
  2.     xmlns:tools="http://schemas.android.com/tools"  
  3.     android:layout_width="match_parent"  
  4.     android:layout_height="match_parent"   
  5.     xmlns:app="http://schemas.android.com/apk/res/org.lmw.demo.slidingtab">  
  6.   
  7.     <org.lmw.demo.slidingtab.widget.PagerSlidingTabStrip  
  8.         android:id="@+id/tabs"  
  9.         android:layout_width="match_parent"  
  10.         android:layout_height="40dp"  
  11.         app:pstsShouldExpand="true"  
  12.         app:pstsUnderlineHeight="2dp"  
  13.         app:pstsIndicatorHeight="2dp"  
  14.         app:pstsIndicatorColor="@android:color/holo_blue_light"  
  15.         app:selectedTabTextColor="@android:color/holo_blue_light"  
  16.         app:pstsDividerColor="@android:color/transparent"  
  17.         app:pstsTabBackground="@drawable/background_tab"  
  18.         android:background="@android:color/white"  
  19.          />  
  20.   
  21.     <android.support.v4.view.ViewPager  
  22.         android:id="@+id/pager"  
  23.         android:layout_width="match_parent"  
  24.         android:layout_height="wrap_content"  
  25.         android:layout_below="@+id/tabs" />  
  26.   
  27. </RelativeLayout>  



0 0