Android TextView实现超链接
2010-02-03 19:13:00 来源:WEB开发网 TextView t3 = (TextView) findViewById(R.id.text3);
t3.setText(
Html.fromHtml(
"text3: Text with a " +
"http://www.google.com\">link> "
+
"created in the Java source code using HTML."));
t3.setMovementMethod(LinkMovementMethod.getInstance());
// text4 illustrates constructing a styled string containing
a
// link without using HTML at all. Again, for a fixed
string
// you should probably be using a string resource, not
a
// hardcoded value.
SpannableString ss = new SpannableString(
"text4:
Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 6,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
ss.setSpan(new
URLSpan("tel:4155551212"), 13, 17,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView t4 = (TextView) findViewById(R.id.text4);
t4.setText(ss);
t4.setMovementMethod(LinkMovementMethod.getInstance());
}
}