Android TextView添加超链接的方法示例

Android TextView添加超链接的方法示例,第1张

概述本文实例讲述了AndroidTextView添加超链接的方法。分享给大家供大家参考,具体如下:

本文实例讲述了AndroID TextVIEw添加超链接的方法。分享给大家供大家参考,具体如下:

public class link extends Activity {  @OverrIDe  protected voID onCreate(Bundle savedInstanceState) {    super.onCreate(savedInstanceState);    setContentVIEw(R.layout.link);    // text1 shows the androID:autolink property,which    // automatically linkifIEs things like URLs and phone numbers    // found in the text. No java code is needed to make this    // work.    // text2 has links specifIEd by putting <a> Tags in the string    // resource. By default these links will appear but not    // respond to user input. To make them active,you need to    // call setMovementMethod() on the TextVIEw object.    TextVIEw t2 = (TextVIEw) findVIEwByID(R.ID.text2);    t2.setMovementMethod(linkMovementMethod.getInstance());    // text3 shows creating text with links from HTML in the Java    // code,rather than from a string resource. Note that for a    // fixed string,using a (localizable) resource as shown above    // is usually a better way to go; this example is intended to    // illustrate how you might display text that came from a    // dynamic source (eg,the network).    TextVIEw t3 = (TextVIEw) findVIEwByID(R.ID.text3);    t3.setText(      HTML.fromHTML(        "<b>text3:</b> Text with a " +        "<a href=\"http://www.Google.com\">link</a> " +        "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),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());  }}

更多关于AndroID相关内容感兴趣的读者可查看本站专题:《Android视图View技巧总结》、《Android布局layout技巧总结》、《Android开发入门与进阶教程》、《Android调试技巧与常见问题解决方法汇总》、《Android多媒体 *** 作技巧汇总(音频,视频,录音等)》、《Android基本组件用法总结》及《Android控件用法总结》

希望本文所述对大家AndroID程序设计有所帮助。

总结

以上是内存溢出为你收集整理的Android TextView添加超链接的方法示例全部内容,希望文章能够帮你解决Android TextView添加超链接的方法示例所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址:https://54852.com/web/1147946.html

(0)
打赏 微信扫一扫微信扫一扫 支付宝扫一扫支付宝扫一扫
上一篇 2022-05-31
下一篇2022-05-31

发表评论

登录后才能评论

评论列表(0条)

    保存