简体   繁体   English

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

[英]EditTexts with links both clickable and editable

I am working with EditText which take WebUrl in input.For that I am using LinkMovementMethod Make links in the EditText clickable. 我正在使用EditText,它将WebUrl作为输入。因为我正在使用LinkMovementMethod使EditText中的链接可单击。

Problem is that : 问题是:

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 wrote the blog post about it several days ago. Daniel Lew几天前写了关于它的博客文章。 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 你可以在这里找到帖子: 使用可点击和可编辑的链接制作EditTexts

check the following code. 检查以下代码。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM