Android、EditText - 如何 "delinkify" 已链接(使用 Linkify class)文本
Android, EditText - How to "delinkify" already linkified (using Linkify class) text
有没有办法删除 Linkify.addLinks(myEditText, Linkify.WEB_URLS);
完成的 "linkification"?
它应该被 Linkify.addLinks(myEditText, 0);
禁用,但它根本不影响链接文本。即使使用 myEditText.setLinksClickable(false);
也完全没有效果(链接仍然可以点击)。
我想出的唯一解决方案有点老套:
myEditText.setText(myEditText.getText().toString());
It should be disabled by Linkify.addLinks(myEditText, 0);
鉴于方法名称以 "add" 开头,我对它完整保留现有内容并不感到惊讶。
Is there a way how to remove "linkification" that was done by Linkify.addLinks(myEditText, Linkify.WEB_URLS);?
您可以尝试从 Spannable
:
中查找并删除所有 URLSpan
(或者 ClickableSpan
)对象
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
有没有办法删除 Linkify.addLinks(myEditText, Linkify.WEB_URLS);
完成的 "linkification"?
它应该被 Linkify.addLinks(myEditText, 0);
禁用,但它根本不影响链接文本。即使使用 myEditText.setLinksClickable(false);
也完全没有效果(链接仍然可以点击)。
我想出的唯一解决方案有点老套:
myEditText.setText(myEditText.getText().toString());
It should be disabled by Linkify.addLinks(myEditText, 0);
鉴于方法名称以 "add" 开头,我对它完整保留现有内容并不感到惊讶。
Is there a way how to remove "linkification" that was done by Linkify.addLinks(myEditText, Linkify.WEB_URLS);?
您可以尝试从 Spannable
:
URLSpan
(或者 ClickableSpan
)对象
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