WordToSpan

General

Category
Free
Tag
Spannable
License
MIT License
Min SDK
16 (Android 4.1 Jelly Bean)
Registered
Aug 23, 2017
Favorites
6
Link
https://github.com/bachors/Android-WordToSpan
See also
SimplifySpan
SpanEZ
Spanner
Android Spans
Makeup

Additional

Language
Java
Version
3.1 (Sep 13, 2018)
Created
Aug 23, 2017
Updated
Sep 13, 2018
Owner
Ican Bachors (bachors)
Contributor
Ican Bachors (bachors)
1
Activity
Badge
Generate
Download
Source code

Blurb

Android-WordToSpan

Small & simple library to create a link url, mail, mention, tag and text highlighter in textView.

Gradle

allprojects {
   repositories {
      ...
      maven { url 'https://jitpack.io' }
   }
}
dependencies {
    ...
    compile 'com.github.bachors:Android-WordToSpan:3.1'
}

Create Link

String myText = "I know http://just.com/anu how to @whisper, And I #know just #how to cry,I know just @where to anu@find.com the answers";
TextView tv = (TextView)findViewById(R.id.tx);

WordToSpan link = new WordToSpan();
link.setColorTAG(Color.GREEN)
 .setColorURL(Color.MAGENTA)
 .setColorPHONE(Color.RED)
 .setColorMAIL(getResources().getColor(R.color.colorPrimary))
 .setColorMENTION(getResources().getColor(R.color.colorAccent))
 .setUnderlineURL(true)
 .setLink(myText)
 .into(tv)
 .setClickListener(new WordToSpan.ClickListener() {
  @Override
  public void onClick(String type, String text) {
   // type: "tag", "mail", "url", "phone", "mention" or "custom"
   Toast.makeText(getApplication(), "Type: " + type + "\nText: " + text, Toast.LENGTH_LONG).show();
  }
 });

Create Highlight

String myText = "Any code and resources in the Android library anywhere love code.";
String keyWord = "any code";
TextView tv = (TextView)findViewById(R.id.tx);

WordToSpan highlight = new WordToSpan();
highlight.setBackgroundHIGHLIGHT(Color.YELLOW)
 .setColorHIGHLIGHT(Color.RED)
 .setHighlight(myText, keyWord)
 .into(tv);

MIT