//链接文字相关
tv_phone=(TextView) findViewById(R.id.tv_lineschedule_phone);
tv_neturl=(TextView) findViewById(R.id.tv_lineschedule_neturl);
//创建一个 SpannableString对象
SpannableString sp_phone = new SpannableString("123456789");//显示内容
SpannableString sp_neturl = new SpannableString("www.dianping.com");
//设置超链接 内容
sp_phone.setSpan(new URLSpan("tel:123456789"), 0, 9,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
sp_neturl.setSpan(new URLSpan("http://www.google.com"), 0, 16,
Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
//设置高亮样式一
sp_phone.setSpan(null, 0 ,9,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
sp_neturl.setSpan(null, 0 ,16,Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
//SpannableString对象设置给TextView
tv_phone.setText(sp_phone);
tv_neturl.setText(sp_neturl);
//设置TextView可点击
tv_phone.setMovementMethod(LinkMovementMethod.getInstance());
tv_neturl.setMovementMethod(LinkMovementMethod.getInstance());
方法二:
tv01 = (TextView)findViewById(R.id.tv01);
tv01.setTextColor(Color.RED);
tv01.setTextSize(22f);
//html字符:超链接
String htmlhref = "<a href=\"http:www.google.com.h快\">百度</a>";
//Html.fromHtml解析HTML,生成String
tv01.setText(Html.fromHtml(htmlhref));
//html字符:只显示超练级,不使用
//tv01.setAutoLinkMask(Linkify.All);
//出来显示还可以点击
tv01.setMovementMethod(LinkMovementMethod.getInstance()
转载于:https://blog.51cto.com/shaotao/1318926