SlidingTabLayout在滑动时修改标题字体颜色,也可在滑动时设置滑动条宽度。

本人参考了http://www.cnblogs.com/chaoxiyouda/p/5265936.html的文章,并在其基础上稍作更改,增加了部分注释

效果图


                    


关键代码:
mainActivity中
slidingTabLayout.setTabTitleTextSize(14);//标题字体大小
slidingTabLayout.setTitleTextColor(Color.BLACK, Color.RED);//标题字体颜色
slidingTabLayout.setTabStripWidth(40);//滑动条宽度
slidingTabLayout.setSelectedIndicatorColors(Color.RED,Color.BLACK,Color.YELLOW);//滑动条颜色
slidingTabLayout.setDistributeEvenly(false); //均匀平铺选项卡
slidingTabLayout.setViewPager(viewPager);//最后调用此方法
SlidingTabStrip自定义控件中:
源代码
canvas.drawRect(left + cutWidth, height - mSelectedIndicatorThickness, right - cutWidth,
        height, mSelectedIndicatorPaint);
更改后代码,想设计什么长度自己去拓展
mSelectionOffset是滚动比例
if(mSelectionOffset<=0.5){
    Log.w("输出0.5以下",right - cutWidth+mSelectionOffset*tabWidth+"");
    canvas.drawRect(left + cutWidth, height - mSelectedIndicatorThickness, right - cutWidth+mSelectionOffset*tabWidth,
            height, mSelectedIndicatorPaint);
}else {
    Log.w("输出0.5以上",right - cutWidth+(mSelectionOffset-0.50)*tabWidth+"");
    canvas.drawRect(left + cutWidth, height - mSelectedIndicatorThickness, (float) (right - cutWidth+(1-mSelectionOffset)*tabWidth),
            height, mSelectedIndicatorPaint);
}


注意:在Android5.0之后如果需要去掉分隔线,去掉悬浮状态,套上AppBarLayout并设置app:elevation="0dp"
<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:elevation="0dp">

    
<org.xufei.sliding_tab.SlidingTabLayout
    android:id="@+id/sliding_tabs"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:translationZ="3dp"
    android:background="#ffffff"/>
</android.support.design.widget.AppBarLayout>
DEMO下载地址:http://download.csdn.net/detail/kac930/9787606
展开阅读全文

没有更多推荐了,返回首页