bold Second String in SpannableString - Android android.text

Android examples for android.text:SpannableString

Description

bold Second String in SpannableString

Demo Code

import android.graphics.Typeface;
import android.text.Spannable;
import android.text.SpannableString;
import android.text.SpannableStringBuilder;
import android.text.style.StyleSpan;
import java.util.Arrays;
import java.util.LinkedHashSet;
import java.util.List;
import java.util.Set;

public class Main{

    public static SpannableString boldSecondString(String first,
            String second) {/*from  w  w  w.  j ava  2  s . c om*/
        return boldSecondString(first, second, "");
    }
    public static SpannableString boldSecondString(String first,
            String second, String third) {
        String formattableMessage = first + " " + second + " " + third;
        SpannableString ss = new SpannableString(formattableMessage.trim());
        int length = first.length() + 1;
        ss.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), length,
                length + second.length(),
                Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
        return ss;
    }

}

Related Tutorials