Simple way to create linked text, such as @username or #hashtag, in Android TextView and EditText

Overview

Simple Linkable Text

Download Android Arsenal

Simple way to create link text, such as @username or #hashtag, in Android TextView and EditText

Installation

Gradle

Add dependency

compile 'com.apradanas.simplelinkabletext:library:1.0.3@aar'

Features

  • Match single strings or regex pattern to set links
  • Change the color of the linked text
  • Set the style of the linked text: BOLD, ITALIC, or BOLD_ITALIC
  • Set the underlined of the linked text
  • Specify click actions of a specific word
  • OnTextChangedListener listener for LinkableEditText

Usage

In your XML layout

LinkableTextView
<com.apradanas.simplelinkabletext.LinkableTextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" />
LinkableEditText
<com.apradanas.simplelinkabletext.LinkableEditText
        android:layout_width="match_parent"
        android:layout_height="wrap_content"/>

In your Activity / Fragment

/*
**	define rules
*/

// find hashtags
Link linkHashtag = new Link(Pattern.compile("(#\\w+)"))
                	.setUnderlined(true)
                	.setTextStyle(TextStyle.ITALIC)
                	.setClickListener(new Link.OnClickListener() {
                    	@Override
                    	public void onClick(String text) {
                       		// do something
                    	}
                	});

// find username
Link linkUsername = new Link(Pattern.compile("(@\\w+)"))
                	.setUnderlined(false)
                	.setTextColor(Color.parseColor("#D00000"))
                	.setTextStyle(TextStyle.BOLD)
                	.setClickListener(new Link.OnClickListener() {
                   		@Override
                    	public void onClick(String text) {
                       		// do something
                    	}
                	});

// match string "string"
Link linkAnd = new Link("string")
               		.setTextColor(Color.BLUE)
               		.setTextStyle(TextStyle.BOLD_ITALIC)
                	.setClickListener(new Link.OnClickListener() {
                   		@Override
                    	public void onClick(String text) {
                       		// do something
                    	}
                	});

List<Link> links = new ArrayList<>();
links.add(linkHashtag);
links.add(linkUsername);
links.add(linkAnd);

/*
**	add rules to LinkableTextView
**	then build()
*/
LinkableTextView textView = (LinkableTextView) findViewById(R.id.textView);
textView.setText("#test #LinkableTextView: detecting #hashtags and @username")
		.addLinks(links)
		.build();

/*
**	add rules to LinkableEditText
**	no need to build()
*/
LinkableEditText editText = (LinkableEditText) findViewById(R.id.editText);
editText.addLinks(links);

License

Copyright 2015 Aditya Pradana Sugiarto

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Comments
  • Autolink not working with this library

    Autolink not working with this library

    I want to show hashtags with web url + contact number. But by using this library , auto-linking stopped working

    android:autoLink="all"

    seems not to working

    opened by beena-patel 0
  • The found links are not in order

    The found links are not in order

    Hi, Can you please suggest how to order the found links ass per their position in the EditText?

    or How to add link position like attribute in the Link Model class?

    opened by mohit-trantor 0
  • Set text to LinkableTextView not working

    Set text to LinkableTextView not working

    The snippet below will not update te text displayed on the TextView. It works fine using the LinkableEDITTEXT though

            tv = (LinkableTextView) findViewById(R.id.heloworld);
    
            Link linkHashtag = new Link(Pattern.compile("(#\\w+)"))
                    .setUnderlined(true)
                    .setTextStyle(Link.TextStyle.BOLD)
                    .setUnderlined(false)
                    .setTextColor(Color.DKGRAY);
            tv.addLink(linkHashtag);
            tv.setText("This does not get set at all");
    
    opened by feresr 1
  • Listview implementation

    Listview implementation

    great library!! I want to give you an advice. can you make mLinks attribute accessible (with getter)? because when you implement this library into ListView or recycleView ViewHolder need to clear the mLinks attribute and fill it again. if you not clear the mLinks after you scroll down and back to up you will add new link into LinkableTextView.

    opened by fahmihidayah 2
  • Build Failed - Merging attribute on Manifest

    Build Failed - Merging attribute on Manifest

    There are a conflict with theme attribute in manifest of my project and this lib.

    Error:(14, 9) Attribute application@theme value=(@style/MyProjectTheme) from AndroidManifest.xml:14:9 is also present at com.apradanas.simplelinkabletext:library:1.0.3:15:9 value=(@style/AppTheme)
    Suggestion: add 'tools:replace="android:theme"' to <application> element at AndroidManifest.xml:9:5 to override Error:Execution failed for task ':app:processDevDebugManifest'.
    
    opened by dsdebastiani 1
Releases(v1.0.3)
Owner
Aditya Pradana Sugiarto
Aditya Pradana Sugiarto
Androids EditText that animates the typed text. EditText is extended to create AnimatedEditText and a PinEntryEditText.

AnimatedEditText for Android This repository contains AnimatedEditText and TextDrawable all of which extend the behaviour of EditText and implement fe

Ali Muzaffar 439 Nov 29, 2022
Android form edit text is an extension of EditText that brings data validation facilities to the edittext.

Android Form EditText Android form edit text is an extension of EditText that brings data validation facilities to the edittext. Example App I built a

Andrea 1.5k Dec 14, 2022
Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Provides easy means to validate with dependencies.

android-formidable-validation Form validation and feedback library for Android. Provides .setText for more than just TextView and EditText widgets. Pr

Linden 147 Nov 20, 2022
A simple and flexible Checked TextView or Checkable TextView

CheckableTextView Checkable TextView [KOTLIN] ⚡ A simple and flexible Checked TextView or Checkable TextView written in Kotlin ⚡ What's New Animation

null 110 Nov 20, 2022
An extension of Android's TextView, EditText and Button that let's you use the font of your choice

AnyTextView (deprecated) Note: AnyTextView is no longer being maintained. I recommend replacing AnyTextView with the Calligraphy library instead. Frus

Hans Petter Eide 165 Nov 11, 2022
A library to show emoji in TextView, EditText (like WhatsApp) for Android

Discontinued This projected is discontinued. Please consider using other alternative, i.e EmojiCompat. Contact me if you want to continue working on a

Hieu Rocker 3.6k Jan 5, 2023
Mentions-TextView - Make Mentions and hashtags clickable in Textview

Mentions Textview Custome Textview with Mentions and hashtags being clickable. D

null 2 Jan 9, 2022
Android library contain custom realisation of EditText component for masking and formatting input text

Masked-Edittext Masked-Edittext android library EditText widget wrapper add masking and formatting input text functionality. Install Maven <dependency

Evgeny Safronov 600 Nov 29, 2022
Add text masking functionality to Android EditText. It will prevent user from inserting not allowed signs, and format input as well.

MaskFormatter MaskFormatter adds mask functionality to your EditText. It will prevent user from inserting not allowed signs, and format input as well.

Azimo Labs 161 Nov 25, 2022
AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size.

AutoscaleEditText AutosizeEditText for Android is an extension of native EditText that offer a smooth auto scale text size. Latest Version How to use

Txus Ballesteros 354 Nov 28, 2022
An Android App example of how to create a custom EditText using DoubleLinkedList Data Structure

DoubleLinkedListEditText Library This is a library to create an EditText based on the Doubly Linked List data structure so that the user can enter cod

Layon Martins 1 Nov 9, 2021
Animation effects to text, not really textview

HTextView Animation effects with custom font support to TextView see iOS Effects see Flutter Effects Screenshot type gif Scale Evaporate Fall Line Typ

hanks 5.5k Jan 5, 2023
A TextView that automatically resizes text to fit perfectly within its bounds.

AutoFitTextView A TextView that automatically resizes text to fit perfectly within its bounds. Usage dependencies { compile 'me.grantland:autofitt

Grantland Chew 4.2k Jan 1, 2023
A Custom TextView with trim text

ReadMoreTextView A Custom TextView with trim text Download To add the ReadMoreTextView library to your Android Studio project, simply add the followin

Borja B. 1.7k Dec 29, 2022
Dealing with Android Text by simple way to get high performance.

Gapo Android RichText RichText supports Hashtag, Mention, Url, Phone Number, Email, Markdown, Custom Span, SeeMore/SeeLess by limited line or length,

GapoWork 8 Oct 20, 2021
Dealing with Android Text by simple way to get high performance.

Gapo Android RichText RichText supports Hashtag, Mention, Url, Phone Number, Email, Markdown, Custom Span, SeeMore/SeeLess by limited line or length,

GapoWork 8 Oct 20, 2021
A simple Android Tag EditText

TagEditText A simple Android Tag EditText. Setup The easiest way to add the TagEditText library to your project is by adding it as a dependency to you

HearSilent 15 May 5, 2022
A editable text with a constant text/placeholder for Android.

ParkedTextView A EditText with a constant text in the end. How to use <com.goka.parkedtextview.ParkedTextView xmlns:app="http://schemas.android.co

goka 270 Nov 11, 2022
RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

RTL marquee text view android right to left moving text - persian - farsi - arabic - urdo

mehran elyasi 4 Feb 14, 2022