Android: Modify the background color, title Font Style, color, icon, and indicator bar color in PagerTabStrip.

Source: Internet
Author: User

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


Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.