3

I'm trying to make some text contain a hyper link for the view.

The html

<p>Random text with a <a href='https://myinsights-test.myunitron.com/' target='_blank' rel='noopener'>Link</a></p>

The text view

    <TextView
            android:id="@+id/notification_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="24sp"
            android:text="@{Html.fromHtml(viewModel.htmlBody)}"
            android:linksClickable="true"
            android:autoLink="web"
            android:clickable="true"
            android:layout_gravity="center_horizontal"/>

the html is coming from a remote server so I don't have full control, although we've agreed to keep it this level of simple.

Cate Daniel
  • 724
  • 2
  • 14
  • 30

1 Answers1

2

This is how you can make link clickable for Android Part Pass you data in HTML.fromHtml as I have passed

textView.setText(Html.fromHtml("<a href=\"http://www.google.com\">This is a link</a>"));
textView.setMovementMethod(LinkMovementMethod.getInstance());
Ankit Tale
  • 1,924
  • 4
  • 17
  • 30