android - 编辑带有可点击和可编辑链接的文本

标签 android android-edittext linkmovementmethod

我正在使用将 WebUrl 作为输入的 EditText。为此,我正在使用 LinkMovementMethod 使 EditText 中的链接可点击。

问题是:

If the last part of the text is a link, clicking anywhere causes the link to be opened.

我想当我点击点击此处编辑区域编辑文本时,它将是可编辑的?

enter image description here

最佳答案

Daniel Lew 几天前写了一篇关于它的博文。他建议下一个解决方案:

// Make links in the EditText clickable
editText.setMovementMethod(LinkMovementMethod.getInstance());

// Setup my Spannable with clickable URLs
Spannable spannable = new SpannableString("http://blog.danlew.net");  
Linkify.addLinks(spannable, Linkify.WEB_URLS);

// The fix: Append a zero-width space to the Spannable
CharSequence text = TextUtils.concat(spannable, "\u200B");

// Use it!
editText.setText(text); 

您可以在这里找到帖子:Making EditTexts with links both clickable and editable

关于android - 编辑带有可点击和可编辑链接的文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34378602/

相关文章:

android - 如何将字符串数组元素转换为整数值?

android - AlarmManager 在库项目中不起作用

android - 如何在 LinearLayout 单元格中对齐两个 TextView?

android - EditText 仅在我单击 ImageButton 时出现

android - 如果您从链接区域开始拖动,LinkMovementMethod 不会滚动

android - setOnItemLongClickListener 没有收到事件

java - Android EditText 空指针异常

android edittext 文本向右对齐,标签向左对齐

android - 使用 ClickableSpan 将 TextView 上的触摸事件重定向到父 View