Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I make links in an EditText clickable?

I have an EditText on Android I'd for which I'd like any embedded urls to be clickable. I used the Linkify class, which has turned them blue and underlined them. However, I can't figure out how to actually make them clickable.

Thanks!

like image 656
lowellk Avatar asked Aug 13 '13 21:08

lowellk


People also ask

How do you make EditText not editable and clickable?

Make EditText non editable in Android To use this just set android:inputType="none" and it will become non editable.


2 Answers

XML:

 android:linksClickable="true"
 android:autoLink="web|email"

JAVA:

TextView textView = (TextView) findViewById(R.id.textViewId);
textView.setText(Html.fromHtml(html));
textView.setMovementMethod(LinkMovementMethod.getInstance());
like image 55
Kamil Lelonek Avatar answered Sep 28 '22 23:09

Kamil Lelonek


For edit text I managed to get links clickable on the following way. First i implemented a Custom MovementMethod as describe here

Java

(Create your edit text from xml or context)

editText.setLinksClickable(true);
editText.setAutoLinkMask(Linkify.WEB_URLS);
editText.setMovementMethod(CustomMovementMethod.getInstance());
//If the edit text contains previous text with potential links
Linkify.addLinks(editText, Linkify.WEB_URLS);

Then to manage that the urls look like links while the user types

editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {


        }

        @Override
        public void afterTextChanged(Editable s) {

                Linkify.addLinks(s, Linkify.WEB_URLS);

        }
    });
like image 34
pleonasmik Avatar answered Sep 29 '22 00:09

pleonasmik