TextView#setMovementMethod(LinkMovementMethod.getInstance()) is breaking link display

醉酒当歌 提交于 2019-12-11 02:31:39

问题


I have a TextView that I am populating with a Spannable made from some HTML.

This code:

textView.setText(Html.fromHtml(textContent, mImageGetter, null));

displays links, but they aren't clickable. This code:

text.setMovementMethod(LinkMovementMethod.getInstance());
textView.setText(Html.fromHtml(textContent, mImageGetter, null));

doesn't display the links. The TextView is specified in the XML as

<TextView
    android:id="@+id/text"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_below="@+id/another_textview"
    android:layout_marginTop="5dp"
    android:autoLink="web"
    android:textColorLink="@color/link_color_unpressed"
    android:textColor="#ffffff"
    android:textSize="18sp" />

Why does LinkMovementMethod, a method that exists entirely to make links in a TextView clickable, stop links from displaying?


回答1:


The culprit was the auto-link method:

<TextView
    ...
    android:autoLink="web"
    ...
    />

Removing this line fixed the problem.



来源:https://stackoverflow.com/questions/15299147/textviewsetmovementmethodlinkmovementmethod-getinstance-is-breaking-link-di

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!