1.
Click on the link and you can jump to the response page.
2. Implementing the Code
TextView1 = (TextView) This.findviewbyid (r.id.textview1); textView2 = (TextView) This.findviewbyid (r.id.textview2 ); String html = "<font color= ' red ' >i love android</font><br>";//Set the font to red, then wrap html + = "<font color= ' # 0000FF ' ><big><i>i love java</i></big></font><p> ';//Set Font blue, large, italic, set to a section of HTML + = "<big><a href= ' http://www.baidu.com ' > Baidu </a></big>";//Add hyperlinks to Baidu text charsequence Charsequence = html.fromhtml (Html); Textview1.settext (charsequence); Textview1.setmovementmethod ( Linkmovementmethod . getinstance ());//Set the information in the text click to produce a hyperlink string text = "My url:http://www.sina.com\n"; text + = " My Email:[email protected]\n "; text + =" My Phone: + 010-87439874 "; textview2.settext (text); Textview2.setmovementmethod ( Linkmovementmethod . getinstance ());
3. Description
Common tags that can be set in TextView are:
- <font>: Sets the color and font.
- <big>: Set Font size
- <small>: Setting the Font s
- <i><b>: Italic Bold
- <a>: Connection URL
- : Pictures
Using these tags, you can use the Html.fromhtml method to convert the string of these tags into an charsequence interface, and then set it in Textview.settext (). If you need to respond to an HTML tag that responds to your settings, you need to set Textview.setmovementmethod (Linkmovementmethod.getinstance ()).
Android:autolink property to set, the following is an introduction to the Android:autolink property:
- None: Default, does not match any connections.
- Web: URL.
- Email: email.
- Phone: Telephone number.
- Map: Match map URLs.
- All: matches all connections.
--------------------------------------------------------------------------------------------------------------- ----------------
Implementation code
public int Getresouceid (String name) {try {//) the object that obtains the field based on the variable name of the resource's ID, using the reflection mechanism to implement the field Field=r.drawable.class.getfield ( name);//Gets and returns the value of the field (static variable) of the resource ID, using the reflection mechanism return Integer.parseint (Field.get (null). ToString ()); catch (Exception e) {//TODO auto-generated catch Blocke.printstacktrace ();} return 0;} @Overrideprotected void OnCreate (Bundle savedinstancestate) {super.oncreate (savedinstancestate); Setcontentview ( R.layout.activity_main); TextView textview= (TextView) This.findviewbyid (r.id.textview1); Textview.settextcolor (Color.Black); Textview.setbackgroundcolor (Color.White); Textview.settextsize (20); String html= "image 1 image 2 image 3<p>"; html+= "image 4<a href= ' http://www.baidu.com ' ></a> image 5--------------------------------------------------------------------------------------------------------------- --------------
Start activity
TextView textview1= (TextView) This.findviewbyid (R.ID.TEXTVIEW1); TextView textview2= (TextView) This.findviewbyid (R.ID.TEXTVIEW2); String text1= "Show Activity1"; String text2= "show Activity2";//mainly used to split the string spannablestring spannablestring=new spannablestring (Text1); Spannablestring spannablestring2=new spannablestring (TEXT2); Spannablestring.setspan (new Clickablespan () {// The entire length of the set string can be clicked valid @overridepublic void OnClick (View arg0) {//TODO auto-generated method stubintent intent=new Intent ( Mainactivity.this, Activity1.class); startactivity (intent);}}, 0, Text1.length (), spannablestring.span_exclusive_ EXCLUSIVE) Spannablestring2.setspan (new Clickablespan () {@Overridepublic void OnClick (View arg0) {//TODO Auto-generated Method Stubintent Intent=new Intent (mainactivity.this, Activity2.class); startactivity (intent);}}, 0, Text2.length (), spannablestring.span_exclusive_exclusive); Textview1.settext (spannablestring); TextView2.setText ( SPANNABLESTRING2);//Set the click Link to jump Textview1.setmovementmethod (Linkmovementmethod.getiNstance ()); Textview2.setmovementmethod (Linkmovementmethod.getinstance ());
--------------------------------------------------------------------------------------------------------------- --------------
Android--TextView (3)