There are a number of ways to implement TextView text links in Android.
In summary, there are about 4 kinds.:
1. When the text appears in the URL, E-mail, telephone number, etc., you can set the TextView Android:autolink property to the corresponding value, if all types come out is android:autolink= "all". Of course, can also be done in Java code, textview01.setautolinkmask (Linkify.all);
2. The text to be processed is written to a resource file, such as String.xml, and then referenced in the Java code (written directly in the code is not feasible, will directly display the text to be processed)
3. Format the text to be placed in the TextView with the fromhtml () method of the HTML class
4. Use spannable or implement it's class, such as spannablestring to format, part of the string.
finally remember to add:
Copy Code code as follows:
Textview.setmovementmethod (Linkmovementmethod.getinstance ());
Example:
Copy Code code as follows:
[Code]
Setcontentview (r.layout.test);
String Source = "<b><font color= #ff0000 > Html View using TextView"
+ "</font></b><br><br><a href= ' http://www.AndroidPeople.com ' >AndroidPeople.com</a>"
+ "<br><br><a href= ' http://www.Android.com ' >Android.com</a>";
TextView TextView = (TextView) Findviewbyid (R.ID.TEXTVIEW01);
Textview.settext (source) (html.fromhtml);
Used to enable links in TextView.
Textview.setmovementmethod (Linkmovementmethod.getinstance ());
Or:
Copy Code code as follows:
TextView textView01 = (TextView) Findviewbyid (R.ID.TEXTVIEW01);
Textview01.setautolinkmask (Linkify.all);
String Autolinktext = "http://student.csdn.net/?232885 my csdn blog";
Textview01.settext (Autolinktext);
Partial connections:
Copy Code code as follows:
spannablestring ss = new Spannablestring ("call:4155551212.");
Ss.setspan (New Stylespan (Typeface.bold), 0, 5, spanned.span_exclusive_exclusive);
Ss.setspan (New Urlspan ("tel:4155551212"), 6, spanned.span_exclusive_exclusive);
Textview04.settext (ss);
Textview04.setmovementmethod (Linkmovementmethod.getinstance ());
There are only 4,155,551,212 parts to be connected.