List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:Main.java
public static SpannableString setTextUnderline(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }// w w w . j a va 2s.c o m SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new UnderlineSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextSub(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/*from w w w.j av a2s .co m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new SubscriptSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextBoldItalic(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/* w w w.j a v a2 s . co m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD_ITALIC), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static void SpannableforStrUtil(Context mContext, String spannableString, TextView textView, int style, int index) { SpannableString styledText1 = new SpannableString(spannableString); styledText1.setSpan(new TextAppearanceSpan(mContext, style), index, index + 1, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); textView.setText(styledText1, TextView.BufferType.SPANNABLE); }
From source file:Main.java
public static SpannableString setTextItalic(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/*from ww w. j a v a 2 s . c o m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.ITALIC), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextSize(String content, int startIndex, int endIndex, int fontSize) { if (TextUtils.isEmpty(content) || fontSize <= 0 || startIndex >= endIndex || startIndex < 0 || endIndex >= content.length()) { return null; }/* w ww.j a v a 2 s . c o m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new AbsoluteSizeSpan(fontSize), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextImg(String content, int startIndex, int endIndex, Drawable drawable) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }// w w w. ja va 2 s . c o m SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new ImageSpan(drawable), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
/** * Applies the given style to a range of the input CharSequence. * @param style The style to apply (see the style constants in {@link Typeface}). * @param input The CharSequence to style. * @param start Starting index of the range to style (will be clamped to be a minimum of 0). * @param end Ending index of the range to style (will be clamped to a maximum of the input * length)./* w ww . ja v a 2 s . c o m*/ * @param flags Bitmask for configuring behavior of the span. See {@link android.text.Spanned}. * @return The styled CharSequence. */ public static CharSequence applyStyleToSpan(int style, CharSequence input, int start, int end, int flags) { // Enforce bounds of the char sequence. start = Math.max(0, start); end = Math.min(input.length(), end); SpannableString text = new SpannableString(input); text.setSpan(new StyleSpan(style), start, end, flags); return text; }
From source file:Main.java
public static SpannableString setTextBold(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/* w w w . j a v a 2 s .c o m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new StyleSpan(android.graphics.Typeface.BOLD), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:Main.java
public static SpannableString setTextBackground(String content, int startIndex, int endIndex, int backgroundColor) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/*from w w w . ja v a 2s . c om*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new BackgroundColorSpan(backgroundColor), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }