0

I am trying to add a link to a website within the text of my TextView.

I'm using Html.fromHtml() method to set the text, and the link is looking as expected, but when I click it, it's not doing anything. I tried setting movementMethod to LinkMovementMethod.getInstance(), but this just gets rid of my formatting, still not working.

agreementText.text = HtmlCompat.fromHtml("I'm familiar with <a href=\"https://www.sololearn.com/terms-of-use\">terms of use</a> of this website.", HtmlCompat.FROM_HTML_MODE_LEGACY)
agreementText.movementMethod = LinkMovementMethod.getInstance()

My TextView:

<TextView
    android:id="@+id/agreement_text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:textSize="12sp"
    android:linksClickable="true"
    android:autoLink="all"/>

1 Answers1

1

I actually found the answer in a comment to this post: Android: textview hyperlink The comment was: "the most correct answer would be to type the HTML anchor tag directly in strings.xml, make sure the autolink property for the TextView is not set, then use setMovementMethod to set the LinkMovementMethod". So if I don't set autoLink or linksClickable, and I set LinkMovementMethod, it's working properly.