带有可点击和可编辑链接的EditText [英] EditTexts with links both clickable and editable

查看:62
本文介绍了带有可点击和可编辑链接的EditText的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am working with EditText which take WebUrl in input.For that I am using LinkMovementMethod Make links in the EditText clickable.

问题在于:

如果文本的最后一部分是链接,则单击任意位置都会导致要打开的链接.

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

我要在单击单击此处进行编辑区域的编辑文本时,该文本是否可编辑?

I want when I am clicking on click here to edit area edittext, It will be editable?

推荐答案

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

Daniel Lew wrote the blog post about it several days ago. He suggests next solution:

// 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); 

您可以在此处找到帖子:

You can find post here: Making EditTexts with links both clickable and editable

这篇关于带有可点击和可编辑链接的EditText的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆