Skip to content Skip to sidebar Skip to footer

Why Link Does Not Work In The Text View?

I have the link in my TextView:

Solution 1:

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"

Solution 2:

Important, if you are using:

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

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

Solution 3:

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

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

    ClickableSpanclickSpan=newClickableSpan() {

        @OverridepublicvoidonClick(View v) {
            switch (v.getId()) {

            case R.id.yourTextViewId :
                IntentlocalIntent=newIntent();
                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);

Solution 4:

enter image description here

Following code is working for me.

String html2 = "<br><br>Fire - <b><ahref=http://www.google.com>google</a></b></br></br>";
        text.append(Html.fromHtml(html2));
        text.setMovementMethod(LinkMovementMethod.getInstance());

Post a Comment for "Why Link Does Not Work In The Text View?"