Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android, EditText - How to "delinkify" already linkified (using Linkify class) text

Is there a way how to remove "linkification" that was done by Linkify.addLinks(myEditText, Linkify.WEB_URLS);?

It should be disabled by Linkify.addLinks(myEditText, 0);, but it doesn't affect the linkified text at all. Even using myEditText.setLinksClickable(false); has absolutely no effect (links are still clickable).

The only solution I have come up with is a little hacky:

myEditText.setText(myEditText.getText().toString());

like image 531
Quark Avatar asked Oct 28 '25 16:10

Quark


1 Answers

It should be disabled by Linkify.addLinks(myEditText, 0);

Given that the method name begins with "add", I am not surprised that it leaves existing stuff intact.

Is there a way how to remove "linkification" that was done by Linkify.addLinks(myEditText, Linkify.WEB_URLS);?

You can try to find and remove all URLSpan (or perhaps ClickableSpan) objects from the Spannable:

Spannable stuff=myEditText.getText();
URLSpan[] spans=stuff.getSpans(0, stuff.length(), URLSpan.class);

for (URLSpan span : spans) {
  stuff.removeSpan(span);
}

// *maybe* need myEditText.setText(stuff), not sure
like image 52
CommonsWare Avatar answered Oct 31 '25 12:10

CommonsWare



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!