Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

android - TextView HTML with anchor link

I have a text in HTML with links external and internal (page navigation). When I use this text in Html.fromHtml and display it in a TextView, external links work, but inside the page itself, it does not go. I have already tried both setMovementMethod and Linkify - everything is not right. I know that it works through WebView, but it will be much faster and more convenient to work this way.

Code sample:

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

Text sample:

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.

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

Put your TextView in ScrollView.

<ScrollView
    android:id="@+id/scroll"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:scrollbars="none" >

    <TextView
        android:id="@+id/textContent"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
</ScrollView>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...