saket / Better-Link-Movement-Method

Attempts to improve how clickable links are detected, highlighted and handled in TextView
Apache License 2.0
783 stars 77 forks source link

Links not highlignting nor Clicking (Libary not having any effect) #38

Closed ismailnurudeen closed 1 year ago

ismailnurudeen commented 4 years ago

I'm trying to open auto links with ChromeCustomTabs, so i intented to use this library to get the url upon click but the library is neither highlighting the links nor is it making them clickable.

Here`s the initial method i tried and nothing happened:

        tv.movementMethod = BetterLinkMovementMethod.newInstance().apply {
            setOnLinkClickListener { textView, url ->
                CustomTabsIntent.Builder().build().launchUrl(activity, Uri.parse(url))
                true
            }
        }

Then i decided to us this and it still isn't working.

        BetterLinkMovementMethod.linkify(Linkify.ALL, tv)
            .setOnLinkClickListener { textView, url ->
                CustomTabsIntent.Builder().build().launchUrl(activity, Uri.parse(url))
                true
            }

When i set autoLink in XML, it highlights the links but just does what standard linkify does, opens the links in the default browser.

saket commented 4 years ago

A LinkMovementMethod is only responsible for highlighting clicks, not inserting links into your text. You'll need to use Linkify.addLinks() before/after you've set the movement method. I should mention this in the README.

When autoLink is used in XML, TextView resets the movement method to the platform LinkMovementMethod so that creates some confusion. You'll have to override it again using textView.movementMethod = BetterLinkMovementMethod.getInstance().

I'd advise against using BetterLinkMovementMethod.linkify because it causes the same confusion as platform's autoLink property.

ismailnurudeen commented 4 years ago

Okay, it makes sense now.

Thanks for the swift response, I would implement that and close the issue if it works.