Example usage for android.text SpannableString setSpan

List of usage examples for android.text SpannableString setSpan

Introduction

In this page you can find the example usage for android.text SpannableString setSpan.

Prototype

public void setSpan(Object what, int start, int end, int flags) 

Source Link

Usage

From source file:Main.java

public static SpannableString getSpannableString(String str, int firstIndex, int endIndex, Object style) {
    SpannableString spannableString = new SpannableString(str);
    spannableString.setSpan(style, firstIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

public static CharSequence bold(CharSequence sequence) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(Typeface.BOLD), 0, sequence.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}

From source file:Main.java

public static Spannable createUnderline(String str) {
    SpannableString contentUnderline = new SpannableString(str);
    contentUnderline.setSpan(new UnderlineSpan(), 0, contentUnderline.length(), 0);

    return contentUnderline;
}

From source file:Main.java

public static CharSequence italic(CharSequence sequence, int length) {
    SpannableString spannable = new SpannableString(sequence);
    spannable.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), 0, length,
            Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannable;
}

From source file:Main.java

/**
 * Create a colored string.//from   ww  w.  ja  v a2 s .co m
 * 
 * @param data The text to be colored.
 * @param color The color for the text.
 * @return A colored string.
 */
public static SpannableString colorString(String data, int color) {
    SpannableString ret = new SpannableString(data);
    ret.setSpan(new ForegroundColorSpan(color), 0, data.length(), 0);
    return ret;
}

From source file:Main.java

public static void setUnderLine(TextView tv) {
    if (tv.getText() != null) {
        String udata = tv.getText().toString();
        SpannableString content = new SpannableString(udata);
        content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
        tv.setText(content);/* w w w . ja  v a2  s.c om*/
        content.setSpan(new UnderlineSpan(), 0, udata.length(), 0);
    } else {
        tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG);
    }
}

From source file:Main.java

public static CharSequence getBoldedString(String value) {
    SpannableString spanned = new SpannableString(value);
    spanned.setSpan(new StyleSpan(Typeface.BOLD), 0, spanned.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spanned;
}

From source file:Main.java

public static SpannableString setTextURL(String content, int startIndex, int endIndex, String url) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }/*from   w  w w.j av  a 2s .  co  m*/

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new URLSpan(url), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);
    return spannableString;
}

From source file:Main.java

public static SpannableString setTextSuper(String content, int startIndex, int endIndex) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }/*from ww w .ja  va 2  s  .  co m*/

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new SuperscriptSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}

From source file:Main.java

public static SpannableString setTextStrikethrough(String content, int startIndex, int endIndex) {
    if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length()
            || startIndex >= endIndex) {
        return null;
    }/*from   w  w  w  . j a v a  2 s .  c  o m*/

    SpannableString spannableString = new SpannableString(content);
    spannableString.setSpan(new StrikethroughSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

    return spannableString;
}