under Line Highlight - Android android.text

Android examples for android.text:SpannableString

Description

under Line Highlight

Demo Code

import android.app.Activity;
import android.app.Service;
import android.content.BroadcastReceiver;
import android.content.ComponentName;
import android.content.Context;
import android.content.pm.PackageManager;
import android.text.Layout;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.Spanned;
import android.text.TextPaint;
import android.text.style.ForegroundColorSpan;
import android.text.style.URLSpan;
import android.text.style.UnderlineSpan;
import android.widget.TextView;
import java.math.BigDecimal;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class Main{

    public static SpannableString underLineHight(String str,
            String underLineStr) {
        if (!str.contains(underLineStr)) {
            return null;
        }/*from  w  w  w  .  jav a2  s.com*/
        SpannableString sp = new SpannableString(str);
        int index = str.indexOf(underLineStr);
        sp.setSpan(new UnderlineSpan(), index,
                index + underLineStr.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return sp;
    }

}

Related Tutorials