我有一个带有外部和内部链接(页面导航)的 HTML 文本。当我在 Html.fromHtml 中使用此文本并将其显示在 TextView 中时,外部链接有效,但在页面本身内部,它不会消失。我已经尝试过 setMovementMethod 和 Linkify - 一切都不对。我知道它可以通过 WebView 工作,但这样工作会更快、更方便。
代码示例:
private void showText(String text) {
TextView content = view.findViewById(R.id.textContent);
content.setText(Html.fromHtml(text, FROM_HTML_MODE_COMPACT));
content.setMovementMethod(LinkMovementMethod.getInstance());
}
文本示例:
The text is long, contained in a ScrollView, has <a name="sdfootnoteAanc" href="#sdfootnoteAsym"> links </a> within itself, such as footnotes. When pressed, the text should scroll to <a name="sdfootnoteAsym" href="#sdfootnoteAanc"> link location </a>, and then back - as often happens on sites.