Java tutorial
//package com.java2s; //License from project: Apache License import android.graphics.*; import android.text.SpannableStringBuilder; import android.text.Spanned; import android.text.style.ClickableSpan; import android.text.style.ForegroundColorSpan; import android.view.View; import java.util.regex.Matcher; import java.util.regex.Pattern; public class Main { public static void makeAboutSpannable(SpannableStringBuilder span, String str_link, String replace, final Runnable on_click) { Pattern pattern = Pattern.compile(str_link); Matcher matcher = pattern.matcher(span); ForegroundColorSpan color_theme = new ForegroundColorSpan(Color.parseColor("#53b7bb")); if (matcher.find()) { span.setSpan(new ClickableSpan() { @Override public void onClick(View widget) { if (on_click != null) on_click.run(); } }, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(color_theme, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (replace != null) span.replace(matcher.start(), matcher.end(), replace); } } }