0

How to run a simple link with the following command?

<TextView
    android:text="text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:id="@+id/textView1" />


TextView textView = FindViewById<TextView>(Resource.Id.textView1); 
textView.TextFormatted = Android.Text.Html.FromHtml("https://www.google.com"); 
textView.MovementMethod = Android.Text.Method.LinkMovementMethod.Instance;

These work:

   textView.TextFormatted = Android.Text.Html.FromHtml("<a href=\"" + "https://www.google.com" + "\">google</a>");
       textView.TextFormatted = Android.Text.Html.FromHtml("<a href=\"" + "https://www.google.com" + "\">https://www.google.com</a>");

This also does not work:

<TextView
    android:text="text"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:clickable="true"
    android:id="@+id/textView1" />

 textView.TextFormatted = Android.Text.Html.FromHtml("<u>" + "https://www.google.com" + "</u>");
user2111639
  • 287
  • 2
  • 5
  • 15

1 Answers1

0

LinkMovementMethod only works for the links in the text .

In Html <a> represents a hyperlink to a url , but <u> is not hyperlink ,it is just an underline .

Avoid using the element where it could be confused for a hyperlink .

ColeX
  • 14,062
  • 5
  • 43
  • 240
  • Hello and thank you. I saw [link] (https://stackoverflow.com/questions/2734270/how-to-make-links-in-a-textview-clickable). Jeshurun wrote that `view.setMovementMethod(LinkMovementMethod.getInstance()); will work with the following (will be highlighted and clickable):` My question was `Some text http://www.google.com` So we must use ``? – user2111639 Jul 30 '21 at 13:47
  • 1