1. Change the Pagertabstrip background color
We set the Background property directly in the layout to:
<android.support.v4.view.viewpager android:id= "@+id/pager" android:layout_width= "Fill_parent " android:layout_height= "Fill_parent" > <android.support.v4.view.pagertabstrip android:id= "@+id/pts " android:layout_width=" wrap_content " android:layout_height=" 50DP " android:layout_gravity=" Top " android:background= "#a05c5ccc"/> </android.support.v4.view.ViewPager>
2. Change the color of the indicator bar
We are able to call in Java code
Pagertabstrip Settabindicatorcolorresource (R.color.green_complete); method to set
3. Change the color of the font to set the title. Color, as well as adding icons for the caption, we were able to rewrite Fragmentstatepageradapter's Getpagetitle method:
@Overridepublic charsequence getpagetitle (int pos) {Spannablestringbuilder SSB = new Spannablestringbuilder ("" + topics[ POS]); Space added before text fordrawable mydrawable = Context.getresources (). getdrawable (R.drawable.card_visited_like); Mydrawable.setbounds (0, 0, mydrawable.getintrinsicwidth (), Mydrawable.getintrinsicheight ()); ImageSpan span = new Imagespan (mydrawable, imagespan.align_baseline); Foregroundcolorspan FCS = new Foregroundcolorspan (color.green);//font color set to green Ssb.setspan (span, 0, 1, spannable.span_ exclusive_exclusive);//Set icon Ssb.setspan (FCS, 1, Ssb.length (), spannable.span_exclusive_exclusive);// Set Font Color Ssb.setspan (new Relativesizespan (1.2f), 1, Ssb.length (), spannable.span_exclusive_exclusive); return SSB;}
Effects such as:
watermark/2/text/ahr0cdovl2jsb2cuy3nkbi5uzxqvtlvqvgjvevpiqg==/font/5a6l5l2t/fontsize/400/fill/i0jbqkfcma==/ Dissolve/70/gravity/center "/>
Project Source: Https://github.com/nuptboyzhb/ViewPageAnimatorDemo
Not for commercial purposes without consent
Of course, you can also consider using the open source code: Https://github.com/astuetz/PagerSlidingTabStrip
Copyright notice: This article Bo Master original articles, blogs, without consent may not be reproduced.
Android: Change the pagertabstrip background color, title font style, color and icon, and the color of the indicator bar