您的位置:首页 > 移动开发 > Android开发

Android学习(1)-TextLink

2016-06-02 14:07 417 查看
以下在看google官方demo发现的一些新API和用法

Html类

该类是可以将普通的字符串格式化为html显示方式,不过有一些标签它不支持。


textViewHtml.setText(
Html.fromHtml(
"<b>text_html_program: Constructed from HTML programmatically.</b>"
+ "  Text with a <a href=\"http://www.google.com\">link</a> "
+ "created in the Java source code using HTML."));


显示的结果

点击跳转到google。

SpannableString类

可以设置字体样式也可以指定某一段字符串可以链接

SpannableString ss = new SpannableString("text_spannable: Manually created spans. Click here to dial the phone.");
ss.setSpan(new StyleSpan(Typeface.BOLD), 0, 39,
Spanned.SPAN_INCLUSIVE_INCLUSIVE);
ss.setSpan(new URLSpan("tel:4155551212"), 40 + 6, 40 + 10,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
TextView textViewSpan = (TextView) findViewById(R.id.text_spannable);
textViewSpan.setText(ss);


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: