Android TextView font color and other styles

Source: Internet
Author: User

Android each TextView text can be set in a variety of color fonts

How to set up Chinese fonts and how to use them: http://blog.csdn.net/pcaxb/article/details/4733680

Spannablestring code used in TextView

Create a Spannablestring object spannablestring MSP = new Spannablestring ("     Font test font size half twice times foreground background color normal bold italic bold italic underline strikethrough x1x2 phone mail website sms MMS map x Axis synthesis "); Set Font (DEFAULT,DEFAULT-BOLD,MONOSPACE,SERIF,SANS-SERIF) msp.setspan (New Typefacespan ("Monospace"), 0, 2,  spanned.span_exclusive_exclusive);    Msp.setspan (New Typefacespan ("serif"), 2, 4, spanned.span_exclusive_exclusive);  Set font size (absolute value, in pixels) msp.setspan (new Absolutesizespan, 4, 6, spanned.span_exclusive_exclusive);  Msp.setspan (New Absolutesizespan (20,true), 6, 8, spanned.span_exclusive_exclusive);    The second parameter, Boolean dip, if true, indicates that the preceding font size is in dip, otherwise pixels, ditto. Sets the font size (relative value, units: pixels) parameter represents how many times the default font size Msp.setspan (new Relativesizespan (0.5f), 8, spanned.span_exclusive_exclusive)  ;  0.5f represents half of the default font size Msp.setspan (new Relativesizespan (2.0f), ten, spanned.span_exclusive_exclusive); 2.0f means twice times the default font size//Set font foreground color Msp.setspan (new Foregroundcolorspan (Color.magenta), X, Spanned.span_exclusive_  EXCLUSIVE); Set foreground color to magenta//Set font background color Msp.setspan (new BackgroUndcolorspan (Color.cyan), spanned.span_exclusive_exclusive); Set the background color to cyan//Set font style normal, bold, italic, Bold italic Msp.setspan (new Stylespan (Android.graphics.Typeface.NORMAL), Max, SPANNED.SPAN_EX  clusive_exclusive);  Normal Msp.setspan (new Stylespan (Android.graphics.Typeface.BOLD), spanned.span_exclusive_exclusive);  Bold Msp.setspan (New Stylespan (Android.graphics.Typeface.ITALIC), N, spanned.span_exclusive_exclusive);  Italic Msp.setspan (New Stylespan (Android.graphics.Typeface.BOLD_ITALIC), spanned.span_exclusive_exclusive);    Coarse italic//Set underline Msp.setspan (new Underlinespan (), +, (spanned.span_exclusive_exclusive);    Set Strikethrough Msp.setspan (new Strikethroughspan (), +, spanned.span_exclusive_exclusive);     Set up the superscript msp.setspan (new Subscriptspan (), spanned.span_exclusive_exclusive, (+);   Subscript Msp.setspan (New Superscriptspan (), $, Notoginseng, spanned.span_exclusive_exclusive); Superscript//hyperlink (need to add Setmovementmethod method additional response) Msp.setspan (New Urlspan ("tel: 4155551212 "), Panax Notoginseng, spanned.span_exclusive_exclusive);     Phone Msp.setspan (New Urlspan ("mailto:[email protected]"), (a), A-p, spanned.span_exclusive_exclusive);     E-mail Msp.setspan (new Urlspan ("http://www.baidu.com"), (a), spanned.span_exclusive_exclusive);     Network Msp.setspan ("sms:4155551212"), Urlspan, spanned.span_exclusive_exclusive);     SMS Using SMS: Or Smsto:msp.setSpan ("mms:4155551212"), Urlspan, spanned.span_exclusive_exclusive);     MMS using MMS: or Mmsto:msp.setSpan (New Urlspan ("geo:38.899533,-77.036476"), +,-spanned.span_exclusive_exclusive); Map//Set font size (relative value, units: pixels) The parameter represents how many times the default font width is Msp.setspan (new Scalexspan (2.0f), $, Spanned.span_exclusive_exclusi VE); 2.0F is twice times the width of the default font, which is twice times the x-axis of the default font, and the height is constant//sets the Bullet Msp.setspan (new Bulletspan ( Android.text.style.bulletspan.standard_gap_width,color.green), 0, spanned.span_exclusive_exclusive); The first parameter represents the width of the bullet, and the second parameter is the color of the bullet TextView View1 = (TextView) findviewbYid (R.ID.TV1); View1.settext (MSP);   View1.setmovementmethod (Linkmovementmethod.getinstance ());


Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

Android TextView font color and other styles

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.