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)
- Myfirsttextview = (textview) findviewbyid (R. Id. myfirsttextview );
- Myfirsttextview. settext ("this is my first textview, ", buffertype. editable );
- /**
- * Set the background color of the text,
- * The text must be set to buffertype. spannable and buffertype. editable.
- */
- Spannable sp = (spannable) myfirsttextview. gettext ();
- // Set the red background
- Sp. setspan (New backgroundcolorspan (color. Red), 3, 8,
- Spannable. span_exclusive_exclusive );
- Sp. setspan (New stylespan (Android. Graphics. typeface. bold_italic ),
- 0, 7, spannable. span_exclusive_exclusive); // set Italic
- Myfirsttextview. settext (SP );
Copy code 2. Implement text hyperlinks
- /************
- * Set hyperlinks
- * Set the textview attribute in layout/*. xml: Android: autolink = "all ".
- * Supported: Web/phone/email/MAP/All/None
- ********/
- Hyperlinktextview = (textview) findviewbyid (R. Id. hyperlinktextview );
- 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 );