EditTexts with links both clickable and editable

前端 未结 2 817
时光说笑
时光说笑 2021-02-10 05:30

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

Problem is that :

2条回答
  •  余生分开走
    2021-02-10 05:36

    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

提交回复
热议问题