Can I set the font size of textview in Android?

Source: Internet
Author: User

1. Set the text style (such as color and italic) in textview. You can set different styles for text in different positions.

(For example, set the characters with an index range of 1-3 to black, and 2-6 to bold)

  1. Myfirsttextview = (textview) findviewbyid (R. Id. myfirsttextview );
  2. Myfirsttextview. settext ("this is my first textview, ", buffertype. editable );
  3. /**
  4. * Set the background color of the text,
  5. * The text must be set to buffertype. spannable and buffertype. editable.
  6. */
  7. Spannable sp = (spannable) myfirsttextview. gettext ();
  8. // Set the red background
  9. Sp. setspan (New backgroundcolorspan (color. Red), 3, 8,
  10. Spannable. span_exclusive_exclusive );

  11. Sp. setspan (New stylespan (Android. Graphics. typeface. bold_italic ),
  12. 0, 7, spannable. span_exclusive_exclusive); // set Italic
  13. Myfirsttextview. settext (SP );

Copy code

2. Implement text hyperlinks

  1. /************
  2. * Set hyperlinks
  3. * Set the textview attribute in layout/*. xml: Android: autolink = "all ".
  4. * Supported: Web/phone/email/MAP/All/None
  5. ********/
  6. Hyperlinktextview = (textview) findviewbyid (R. Id. hyperlinktextview );
  7. Hyperlinktextview. settext ("My blog-> http://orgcent.com ");

Copy code

<Textview
Android: layout_width = "fill_parent"
Android: layout_height = "wrap_content"
Android: text = "@ string/main"
Android: textsize = "65px"

/>

You can add an Android: textsize = "" in XML or in mtextview. settextsize (size );

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.