AutoLinkTextViewV2

Additional

Language
Kotlin
Version
N/A
Created
Sep 29, 2019
Updated
Oct 2, 2019
Owner
Arman (armcha)
Contributors
Arman (armcha)
ahmetcj4
JakeWoki
liamcottle
RockySteveJobs
5
Activity
Badge
Generate
Download
Source code
APK file

Announcement

AutoLinkTextView V2

AutoLinkTextViewV2 is the new version of the AutoLinkTextView.

The main differences between the old and new version are

  • Fully migration to Kotlin
  • Added several new features
  • Some improvements and fixes

It supports automatic detection and click handling for

  • Hashtags (#)
  • Mentions (@)
  • URLs (http://)
  • Phone Numbers
  • Emails
  • Custom Regex

.

The current minSDK version is API level 16.

Download sample apk

Features

  • Default support for Hashtag, Mention, Link, Phone number and Email
  • Support for custom types via regex
  • Transform url to short clickable text
  • Ability to apply multiple spans to any mode
  • Ability to set specific text color
  • Ability to set pressed state color


Setup and Usage

Add AutoLinkTextView to your layout

<io.github.armcha.autolink.AutoLinkTextView
    android:id="@+id/autolinkTextView"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content" />
val autoLinkTextView = findViewById<AutoLinkTextView>(R.id.autolinkTextView);

Add one or multiple modes

autoLinkTextView.addAutoLinkMode(
                MODE_HASHTAG,
                MODE_URL)

Add url transformations for transforming them to short clickable text

autoLinkTextView.addUrlTransformations( "https://google.com" to "Google", "https://en.wikipedia.org/wiki/Wear_OS" to "Wear OS")

Or you can attach urlProcessor and transform it

autoLinkTextView.attachUrlProcessor { originalUrl:String->when {
        originalUrl.startsWith("https://en.wikipedia") ->"Wiki"
        originalUrl.contains("android") ->"Android"else-> originalUrl
    }
}