1. Modify the background color in PagerTabStrip
You can directly set the background attribute in the layout:
2. Modify the color of the indicator bar
We can call
SetTabIndicatorColorResource (R. color. green_complete) of pagertabstrip;
3. Modify the color and color of the title Font and add an icon to the title. We can rewrite the getPageTitle method of FragmentStatePagerAdapter:
@ 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); // set the font color to GREEN ssb. setSpan (span, 0, 1, Spannable. SPAN_EXCLUSIVE_EXCLUSIVE); // you can specify the ssb icon. setSpan (fcs, 1, ssb. length (), Spannable. SPAN_EXCLUSIVE_EXCLUSIVE); // set the font color ssb. setSpan (new RelativeSizeSpan (1.2f), 1, ssb. length (), Spannable. SPAN_EXCLUSIVE_EXCLUSIVE); return ssb ;}
The effect is as follows:
Project Source: https://github.com/nuptboyzhb/ViewPageAnimatorDemo
Not for commercial purposes without permission