1.這些類似html標簽可以用Html.fromHtml方法將html標簽字符串轉化成CharSequence對象,然后再TextView中進行設置:
如:
在.xml文件中
<TextView
android:id="@+id/textview1"
android:padding="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
在.java文件中
textView1 = (TextView) findViewById(R.id.textview1);
String html = "<font color='red'>I love android </font><br>";
html+="<font color='#0000ff'><big><i>I love android</i> </big></font><p>";
html+="<big><a href='http://www.baidu.com'>百度</a></big>";
CharSequence charSequence = Html.fromHtml(html);
textView1.setText(charSequence);
textView1.setMovementMethod(LinkMovementMethod.getInstance());//點擊的時候產生超鏈接
2.如果想在顯示文本中將URL地址,郵箱地址,電話超鏈接的效果可以使用android::autoLink設置.
如:
在.xml文件中
<TextView
android:id="@+id/textview2"
android:padding="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:autoLink="all"
android:textSize="20sp"
android:text="@string/link_text"
/>
strings.xml中:
<string name="link_text"><a href="tel:18870076184">打電話</a></string>
在.java文件中:
String text = "我的URL:http://www.sina.com\n";
text+="我的email:abcd@126.com\n";
text+="我的電話:18870076184";
textView2.setText(text);
textView2.setMovementMethod(LinkMovementMethod.getInstance());
運行結果: