List of usage examples for android.text SpannableString setSpan
public void setSpan(Object what, int start, int end, int flags)
From source file:com.vuze.android.remote.AndroidUtilsUI.java
public static void linkify(TextView tv) { tv.setMovementMethod(LinkMovementMethod.getInstance()); CharSequence t = tv.getText(); if (!(t instanceof SpannableString)) { return;//w ww . j a v a 2s . c om } SpannableString text = (SpannableString) t; int len = text.length(); int next; for (int i = 0; i < text.length(); i = next) { next = text.nextSpanTransition(i, len, URLSpan.class); URLSpan[] old = text.getSpans(i, next, URLSpan.class); for (int j = old.length - 1; j >= 0; j--) { text.removeSpan(old[j]); UrlSpan2 span2 = new UrlSpan2(old[j].getURL()); text.setSpan(span2, i, next, Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); } } }
From source file:com.gm.goldencity.util.Utils.java
/** * Apply typeface to a plane text and return spannableString * * @param text Text that you want to apply typeface * @param typeface Typeface that you want to apply to your text * @return spannableString/*from w w w.j a va 2 s . c o m*/ */ public static SpannableString applyTypefaceToString(String text, final Typeface typeface) { SpannableString spannableString = new SpannableString(text); spannableString.setSpan(new MetricAffectingSpan() { @Override public void updateMeasureState(TextPaint p) { p.setTypeface(typeface); // Note: This flag is required for proper typeface rendering p.setFlags(p.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); } @Override public void updateDrawState(TextPaint tp) { tp.setTypeface(typeface); // Note: This flag is required for proper typeface rendering tp.setFlags(tp.getFlags() | Paint.SUBPIXEL_TEXT_FLAG); } }, 0, spannableString.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return spannableString; }
From source file:com.just.agentweb.AgentWebUtils.java
static void show(View parent, CharSequence text, int duration, @ColorInt int textColor, @ColorInt int bgColor, CharSequence actionText, @ColorInt int actionTextColor, View.OnClickListener listener) { SpannableString spannableString = new SpannableString(text); ForegroundColorSpan colorSpan = new ForegroundColorSpan(textColor); spannableString.setSpan(colorSpan, 0, spannableString.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); snackbarWeakReference = new WeakReference<>(Snackbar.make(parent, spannableString, duration)); Snackbar snackbar = snackbarWeakReference.get(); View view = snackbar.getView(); view.setBackgroundColor(bgColor);//from w w w . j a v a 2 s .c om if (actionText != null && actionText.length() > 0 && listener != null) { snackbar.setActionTextColor(actionTextColor); snackbar.setAction(actionText, listener); } snackbar.show(); }
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
public static SpannableString createBoldSpan(String text, String toBold) { SpannableString span = new SpannableString(text); int start = text.indexOf(toBold); int end = start + toBold.length(); span.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span;//from w w w . j a v a2s .c om }
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
public static SpannableString createBoldColorSpan(String text, String toBold, int color) { SpannableString span = new SpannableString(text); int start = text.indexOf(toBold); int end = start + toBold.length(); span.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span;/*from ww w .j av a 2s . c om*/ }
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
public static SpannableString createBoldColorSpan(String text, String toBold, int color, int pointSizePixels) { SpannableString span = new SpannableString(text); int start = text.indexOf(toBold); int end = start + toBold.length(); span.setSpan(new android.text.style.StyleSpan(android.graphics.Typeface.BOLD), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(new AbsoluteSizeSpan(pointSizePixels), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span;// w w w . j a v a2 s . c o m }
From source file:com.forrestguice.suntimeswidget.SuntimesUtils.java
public static SpannableString createColorSpan(String text, String toColorize, int color) { SpannableString span = new SpannableString(text); int start = text.indexOf(toColorize); int end = start + toColorize.length(); span.setSpan(new ForegroundColorSpan(color), start, end, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return span;/*from ww w.ja va 2s . com*/ }
From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java
private Spannable makeAsteriskSpan() { SpannableString sb = new SpannableString("*"); sb.setSpan(new AsteriskSpan(getContext()), sb.length() - 1, sb.length(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); return sb;// ww w .ja v a 2 s .c o m }
From source file:com.example.sample2.MainActivity.java
private void setActionBarTitle() { if (getSupportActionBar() == null) return;//from w w w . java 2 s . c om TypefaceSpan span = new TypefaceSpan(this, "Audiowide-Regular"); ForegroundColorSpan colorSpan = new ForegroundColorSpan(Color.CYAN); SpannableString title = new SpannableString("TextViews2"); title.setSpan(span, 0, title.length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); title.setSpan(colorSpan, 4, title.length() - 1, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); getSupportActionBar().setTitle(title); }
From source file:io.github.hidroh.materialistic.widget.preference.HelpListView.java
@Override protected void onFinishInflate() { super.onFinishInflate(); ((TextView) findViewById(R.id.item_new).findViewById(R.id.rank)).append(makeAsteriskSpan()); SpannableString spannable = new SpannableString("+5"); spannable.setSpan(new SuperscriptSpan(), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new RelativeSizeSpan(0.6f), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); spannable.setSpan(new ForegroundColorSpan(ContextCompat.getColor(getContext(), R.color.greenA700)), 0, spannable.length(), Spanned.SPAN_INCLUSIVE_EXCLUSIVE); ((TextView) findViewById(R.id.item_promoted).findViewById(R.id.rank)).append(spannable); TextView comments = (TextView) findViewById(R.id.item_new_comments).findViewById(R.id.comment); SpannableStringBuilder sb = new SpannableStringBuilder("46"); sb.append(makeAsteriskSpan());//from ww w. j ava 2 s.co m comments.setText(sb); }