本文介绍了TextView#setMovementMethod(LinkMovementMethod.getInstance())正在断开链接显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TextView,其中填充了由某些HTML制成的Spannable.

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

此代码:

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));

显示链接. TextView在XML中指定为

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" />

为什么LinkMovementMethod(一种完全可以使TextView中的链接可单击的方法)会停止显示链接?

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

推荐答案

罪魁祸首是自动链接方法:

The culprit was the auto-link method:

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

删除此行可解决此问题.

Removing this line fixed the problem.

这篇关于TextView#setMovementMethod(LinkMovementMethod.getInstance())正在断开链接显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

11-02 01:27