在AndroidStudio中使用PagerSlidingTabStrip

来源:互联网 发布:html5引导动画源码 编辑:程序博客网 时间:2024/04/30 23:04

今天花了一天的时间,写了一个属于自己的开发框架,其中有一个是PagerSlidingTabStrip+fragment+viewpager框架,用了新的PagerSlidingTabStrip,这里记一下经验。

1.首先在AndroidStudio中加载依赖:

<span style="font-size:18px;">compile 'com.jpardogo.materialtabstrip:library:1.0.9'</span>

2.布局中声明:

<com.astuetz.PagerSlidingTabStrip        android:id="@+id/tabs"        app:pstsShouldExpand="true"        app:pstsIndicatorColor="@color/lightred"        app:pstsTextColorSelected="@color/lightred"        android:layout_width="match_parent"        android:layout_height="40dp"        android:background="@color/white"        android:textColor="@color/lightblack" />

3.java代码中使用:

viewPager.setAdapter(pageAdapter);tabs.setViewPager(viewPager);

4.相关属性,这里直接从github上copy下来了:

个人认为有上面定义的属性已经足够使用了

Notes about some of the native attr:

  • android:textColor Non selected tabs text color. If you DO define textColor It will be apply toNON selected tabs and NO ALPHA will be applied to them, the colour you define is the one you will see. If you want to define a half transparent color in textColor, you can pass #80FFFFFF (That's an example for half transparent white)
  • android:textSize Tab text size
  • android:paddingLeft or android:paddingRight layout padding. If you apply both, they should be balanced. PR #69 have a good explanation of this behaviour.

Custom attr:

  • pstsIndicatorColor Color of the sliding indicator. textPrimaryColor will be it's default color value.
  • pstsUnderlineColor Color of the full-width line on the bottom of the view. textPrimaryColor will be it's default color value.
  • pstsUnderlineHeight Height of the full-width line on the bottom of the view.
  • pstsTextAlpha Set the text alpha transparency for non selected tabs. Range 0..255. 150 is it's default value. It WON'T be use if textColor is defined in the layout. If textColor is NOT defined, It will be apply to the non selected tabs.
  • pstsTextColorSelected Set selected tab text color. textPrimaryColor will be it's default color value.
  • pstsTextStyle Set the text style, default bold.
  • pstsTextSelectedStyle Set the text style of the selected tab, default bold.
  • pstsTextAllCaps If true, all tab titles will be upper case, default true.
  • pstsDividerColor Color of the dividers between tabs. textPrimaryColor will be it's default color value.
  • pstsDividerPadding Top and bottom padding of the dividers.
  • pstsDividerWidth Stroke width of divider line, defaults to 0.
  • pstsIndicatorHeightHeight of the sliding indicator.
  • 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.
  • pstsPaddingMiddle If true, the tabs start at the middle of the view (Like Newsstand google app).

0 0
原创粉丝点击