TextView里的超链接的实现:
能自定义换成超链接的文字。而且能多所有相同文字同时处理:
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
TextView tv = (TextView) findViewById(R.id.textView1);
tv.setMovementMethod(ScrollingMovementMethod.getInstance());
Pattern pattern = Pattern.compile("Android");
final String strUrl = "http://baike.baidu.com/subview/1241829/9322617.htm";
Linkify.TransformFilter filter = new Linkify.TransformFilter() {
@Override
public String transformUrl(Matcher match, String url) {
return strUrl;
}
};
Linkify.addLinks(tv, pattern, strUrl, null, filter);
}
}效果图:
本文介绍如何在Android应用中使用TextView自定义文字为超链接,并批量处理相同文字的方法。通过Pattern和Linkify配合使用,实现对特定字符串进行超链接转换。
2299

被折叠的 条评论
为什么被折叠?



