Why link does not work in the text view?

Important, if you are using:

if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.N) {
    textView.setText(Html.fromHtml("<a href=https://www.google.com/>Click</a>", Html.FROM_HTML_MODE_LEGACY));
} else {
    textView.setText(Html.fromHtml("<a href=https://www.google.com/>Click</a>"));
}
textView.setClickable(true);
textView.setMovementMethod(LinkMovementMethod.getInstance());

Do not set android:autoLink="all" or android:autoLink="web" in the xml, because with that it doesn't work!


you can use http link this way:

   mLink = (TextView) findViewById(R.id.link);
      if (mLink != null) {
        mLink.setMovementMethod(LinkMovementMethod.getInstance());
     }

In XML:

android:autoLink="all"

TextView yourTextView = (TextView) findViewById(R.id.yourTextViewId );

    yourTextView.setMovementMethod(LinkMovementMethod.getInstance());
    Spannable spans = (Spannable) yourTextView.getText();

    ClickableSpan clickSpan = new ClickableSpan() {

        @Override
        public void onClick(View v) {
            switch (v.getId()) {

            case R.id.yourTextViewId :
                Intent localIntent = new Intent();
                localIntent.setAction("android.intent.action.VIEW");
                localIntent.setData(Uri.parse("YOUR LINK"));
                startActivity(localIntent);
                break;
            }

        }
    };
    spans.setSpan(clickSpan, 0, spans.length(),
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);