there are about 5 ways to summarize.:
1. When the text appears in the URL, e-mail, phone number, etc., you can set the TextView Android:autolink property to the corresponding value, if all the types are out is android:autolink= "all". Of course you can do it 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 is processed)
3. Use the Fromhtml () method of the HTML class to format the text to be placed in the TextView 4. Set the Paint property of the TextView: Tvtest.getpaint (). SetFlags (Paint. Underline_text_flag); Underline
5. Use spannable or implement its class, such as spannablestring, to format part of the string. Also attach a blog introduction: Android textview text through the spannablestring to set the hyperlink, color, font and other properties if it is in the resource file: 1, the string resource set the underscore attribute
<resources> <string name= "Hello" ><u>phone:0123456</u></string> <string Name= "App_name" >MyLink</string></resources>
Let TextView refer to the name of the string resource directly.
2. TextView Setting Autolink Property
<textview xmlns:android= "Http://schemas.android.com/apk/res/android"
Android:id= "@+id/text1"
Android:layout_width= "Match_parent"
android:layout_height= "Match_parent"
android:autolink= "All"
android:text= "@string/link_text_auto"/>
If it is in the code:
1. Using html.fromhtml ()
TextView TextView = (TextView) Findviewbyid (r.id.tv_test); Textview.settext (html.fromhtml ("<u>" + "0123456" + "</u>"));
2. Properties of paint using TextView
Tvtest.getpaint (). SetFlags (Paint. Underline_text_flag); Underline
Tvtest.getpaint (). Setantialias (true);//anti-aliasing
3. Using Spannablestring class
spannablestring content = new spannablestring (str);
Content.setspan (new Underlinespan, 0, Str.length (), 0);
Custom hyperlink style inside code:
TextView tv=new TextView (this);
Tv.settext (html.fromhtml ("<a href=\" http://blog.csdn.net/caiyunfreedom\ "> Custom hyperlink Style </a>"));
When you click a link, you must set the Movementmethod object whenever you want to perform an action.
Tv.setmovementmethod (Linkmovementmethod.getinstance ());
Charsequence text = Tv.gettext ();
if (text instanceof spannable) {
int end = Text.length ();
Spannable sp = (spannable) tv.gettext ();
urlspan[] urls = Sp.getspans (0, end, Urlspan.class);
SpannableStringBuilder style = new Spannablestringbuilder (text);
Style.clearspans (); Should clear old spans
for (Urlspan url:urls) {
Urlspan myurlspan= New Urlspan (Url.geturl ());
Style.setspan (Myurlspan,sp.getspanstart (URL), sp.getspanend (URL), spannable.span_exclusive_exclusive);
Style.setspan (New Foregroundcolorspan (color.red), Sp.getspanstart (URL),
Sp.getspanend (URL), spannable.span_exclusive_exclusive);//set foreground color to red
}
Tv.settext (style);
}
In another article, there are several specific examples that can be consulted:
http://hunankeda110.iteye.com/blog/1420470
Several ways to add an underscore to Android TextView