1、代码中增加。
TextView textView = (TextView)findViewById(R.id.myTextView);
Linkify.addLinks(textView, Linkify.WEB_URLS|Linkify.EMAIL_ADDRESSES);
如果想让显示超链接的形式,但不能直接点击链接,增加android:linksClickable="false"
请注意,加上Linkify要在setText之后,否则不起作用。惨痛的教训。
?
2、xml中增加
?
?
<TextView android:id="@+id/text_view"
? ? ? ? ? ? ? ? ? ? android:autoLink="all"
? ? ? ? ? ? ? ? ? ? android:paddingTop="1dip"
? ? ? ? ? ? ? ? ? ? android:paddingBottom="3dip"
? ? ? ? ? ? ? ? ? ? android:layout_width="wrap_content"
? ? ? ? ? ? ? ? ? ? android:layout_height="wrap_content"
? ? ? ? ? ? ? ? ? ? android:linksClickable="false"
? ? ? ? ? ? ? ? ? ? android:text="http://www.csdn.net dsfdfsadasfasdf"
? ? ? ? ? ? ? ? ? ? android:textAppearance="?android:attr/textAppearanceSmall"
? ? ? ? ? ? ? ? ? ? android:textSize="18sp"
? ? ? ? ? ? ? ? ? ? android:layout_gravity="left"
? ? ? ? ? ? ? ? ? ? />
?
3、 如果实在某个ListView中的Item使用,autolink会获取到焦点,而使Item无法点击。
只需要在item的xml文件中的根布局中加上一句: android:descendantFocusability="blocksDescendants" 屏蔽item中抢夺focus的控件权限即可解决问题。 |