Skip to content

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

License

Notifications You must be signed in to change notification settings

bachors/Android-WordToSpan

Repository files navigation

Android-WordToSpan

Android Arsenal Release

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

gif

String myText = "I know http://just.com/anu how to @whisper, And I #know just #how to cry,I know just @where to [email protected] 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

gif

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

About

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

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages