WordToSpan

Additional

Language
Java
Version
3.1 (Sep 13, 2018)
Created
Aug 23, 2017
Updated
Nov 1, 2019 (Retired)
Owner
Ican Bachors (bachors)
Contributors
Ican Bachors (bachors)
Chintan Rathod (ChintanRathod)
2
Activity
Badge
Generate
Download
Source code

Advertisement

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 {
    ...
    implementation '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