List of usage examples for android.text SpannableString SpannableString
public SpannableString(CharSequence source)
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 void setPartialColor(TextView tv, int start, int end, int textColor) { String s = tv.getText().toString(); Spannable spannable = new SpannableString(s); spannable.setSpan(new ForegroundColorSpan(textColor), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(spannable);/*from w w w . ja v a 2s . c o m*/ }
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);/*from w w w . jav a2 s.c o m*/ content.setSpan(new UnderlineSpan(), 0, udata.length(), 0); } else { tv.getPaint().setFlags(Paint.UNDERLINE_TEXT_FLAG); } }
From source file:Main.java
public static CharSequence scaleEmotions(String text) { SpannableString spannableString = new SpannableString(text); for (String emotion : emotions) { Pattern pattern = Pattern.compile(emotion); Matcher matcher = pattern.matcher(text); while (matcher.find()) { int start = matcher.start(); int end = matcher.end(); spannableString.setSpan(new RelativeSizeSpan(1.2f), start, end, Spanned.SPAN_INCLUSIVE_EXCLUSIVE); }//from www .j a va 2s . co m } return spannableString; }
From source file:Main.java
/** * @param text/*from www . ja v a 2 s . com*/ * @param color * @param start * @param end * @return */ public static SpannableString highLight(CharSequence text, int color, int start, int end) { SpannableString span = new SpannableString(text); span.setSpan(new ForegroundColorSpan(color), start, end, SpannableString.SPAN_EXCLUSIVE_EXCLUSIVE); return span; }
From source file:Main.java
public static void setPartialSizeAndColor(TextView tv, int start, int end, int textSize, int textColor) { String s = tv.getText().toString(); Spannable spannable = new SpannableString(s); spannable.setSpan(new AbsoluteSizeSpan(textSize, false), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(textColor), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); tv.setText(spannable);// w w w .ja v a 2s. co m }
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
public static SpannableString StringToBitMap(Context context, String msg) { SpannableString ss = new SpannableString(msg); Pattern p = Pattern.compile("/mnt/sdcard/.+?\\.\\w{3}"); Matcher m = p.matcher(msg);/*from w w w . ja v a2 s . com*/ while (m.find()) { Bitmap bitmap = BitmapFactory.decodeFile(m.group()); ImageSpan imageSpan = new ImageSpan(context, bitmap); ss.setSpan(imageSpan, m.start(), m.end(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); } return ss; }
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 setTextSub(String content, int startIndex, int endIndex) { if (TextUtils.isEmpty(content) || startIndex < 0 || endIndex >= content.length() || startIndex >= endIndex) { return null; }/*from www .j av a 2s . co m*/ SpannableString spannableString = new SpannableString(content); spannableString.setSpan(new SubscriptSpan(), startIndex, endIndex, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }