List of usage examples for android.text.style ForegroundColorSpan ForegroundColorSpan
public ForegroundColorSpan(@NonNull Parcel src)
From source file:Main.java
public static CharSequence convertStringToShowErrorInEditText(String string) { ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(Color.WHITE); SpannableStringBuilder spannableStringBuilder = new SpannableStringBuilder(string); spannableStringBuilder.setSpan(foregroundColorSpan, 0, string.length(), 0); return spannableStringBuilder; }
From source file:Main.java
public static CharSequence getError(String msg) { int color = Color.WHITE; ForegroundColorSpan foregroundColorSpan = new ForegroundColorSpan(color); SpannableStringBuilder string = new SpannableStringBuilder(msg); string.setSpan(foregroundColorSpan, 0, msg.length(), 0); return string; }
From source file:Main.java
public static CharSequence color(int color, CharSequence sequence) { SpannableString spannable = new SpannableString(sequence); spannable.setSpan(new ForegroundColorSpan(color), 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 ww. j a v a2 s . c om*/ }
From source file:Main.java
/** * @param text/*from w w w .ja v a 2s .c om*/ * @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
/** * Set an error message to a text view/*w w w . j av a2 s. c o m*/ * * @param color Set the color foreground for the span * @param message Message to be shown * @param txtView Text View to which the message will be added */ public static void setError(int color, String message, TextView txtView) { ForegroundColorSpan fgcspan = new ForegroundColorSpan(color); SpannableStringBuilder ssbuilder = new SpannableStringBuilder(message); ssbuilder.setSpan(fgcspan, 0, message.length(), 0); txtView.setError(ssbuilder); }
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);//from w w w.j a v a 2 s . c om }
From source file:Main.java
public static SpannableStringBuilder getFrontTextStyle(String frontText, String afterText, int frontColor, int frontTextSize) { StringBuilder sb = new StringBuilder(); sb.append("/").append(afterText); int len = sb.length(); sb.insert(0, frontText);//from w ww.j a va 2 s.c o m SpannableStringBuilder style = new SpannableStringBuilder(sb); style.setSpan(new ForegroundColorSpan(frontColor), 0, sb.length() - len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); style.setSpan(new AbsoluteSizeSpan(frontTextSize), 0, sb.length() - len, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); return style; }
From source file:Main.java
public static void makeAboutSpannable(SpannableStringBuilder span, String str_link, String replace, final Runnable on_click) { Pattern pattern = Pattern.compile(str_link); Matcher matcher = pattern.matcher(span); ForegroundColorSpan color_theme = new ForegroundColorSpan(Color.parseColor("#53b7bb")); if (matcher.find()) { span.setSpan(new ClickableSpan() { @Override// w ww.j av a2s. c o m public void onClick(View widget) { if (on_click != null) on_click.run(); } }, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); span.setSpan(color_theme, matcher.start(), matcher.end(), Spanned.SPAN_EXCLUSIVE_EXCLUSIVE); if (replace != null) span.replace(matcher.start(), matcher.end(), replace); } }
From source file:Main.java
public static void setTextViewCharHilighted(TextView textView, String text, int startIndex, int endIndex, int color) { if (textView == null || text == null) { return;/*from w w w . java 2 s.c o m*/ } if (startIndex < 0) { return; } if (endIndex > text.length()) { return; } textView.setText(text, BufferType.SPANNABLE); Spannable span = (Spannable) textView.getText(); if (span == null) { return; } span.setSpan(new ForegroundColorSpan(color), startIndex, endIndex, Spannable.SPAN_EXCLUSIVE_EXCLUSIVE); }