我正在使用在输入中使用 WebUrl 的 EditText。为此,我LinkMovementMethod
在 EditText 中使用 Make 链接可点击。
问题是:
如果文本的最后一部分是链接,则单击任意位置都会打开链接。
我想当我点击单击此处编辑区域编辑文本时,它会是可编辑的吗?
我正在使用在输入中使用 WebUrl 的 EditText。为此,我LinkMovementMethod
在 EditText 中使用 Make 链接可点击。
问题是:
如果文本的最后一部分是链接,则单击任意位置都会打开链接。
我想当我点击单击此处编辑区域编辑文本时,它会是可编辑的吗?
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);
你可以在这里找到帖子:使用可点击和可编辑的链接制作 EditTexts
检查以下代码。
EditText inputText;
//Edittext is clickable at right side.
inputText.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
final int DRAWABLE_LEFT = 0;
final int DRAWABLE_TOP = 1;
final int DRAWABLE_RIGHT = 2;
final int DRAWABLE_BOTTOM = 3;
if (event.getAction() == MotionEvent.ACTION_UP) {
if (event.getRawX() >= (inputText.getRight() - inputText.getCompoundDrawables()[DRAWABLE_RIGHT].getBounds().width())) {
//write your logic
return true;
}
}
return false;
}
});