TextView中加入超链接的方式很多,但下面的方式应该的最简便合理的
strings.xml中定义字串
<string name="blog"><a href="http://blog.youkuaiyun.com/jonahzheng">东子的博客</a></string>
布局中textview定义,并且textview的text引用stings.xml中定义的‘blog’
<TextView
android:id="@+id/tv_blog"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:text="@string/blog"
android:textColor="#F5F5F5"
android:textSize="18sp" />
java代码中
加入
TextView tv_blog =(TextView) findViewById(R.id.tv_blog);tv_blog.setMovementMethod(LinkMovementMethod.getInstance());

本文介绍了一种在Android TextView中简单有效地添加超链接的方法。通过在strings.xml文件中定义带有HTML标签的字符串资源,并结合使用LinkMovementMethod,使得TextView能够响应点击事件并跳转到指定的网页。
972

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



