Android: Change the pagertabstrip background color, title font style, color and icon, and the color of the indicator bar

Source: Internet
Author: User

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

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.