带有可点击和可编辑链接的 EditTexts

EditTexts with links both clickable and editable

我正在使用 EditText,它在我正在使用的 input.For 中采用 WebUrl LinkMovementMethod 在 EditText 中创建可点击的链接。

问题是:

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

我想当我点击click here to edit area edittext, 它将是可编辑的?

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

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

您可以在此处找到 post:Making EditTexts with links both clickable and editable

检查以下代码。

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