For pedals that prefer to do utils classes for this:
public static SpannableStringBuilder makeTextBold (Activity activity, String string, int fromCharIndex, int toCharIndex) { return makeTextBold(activity, new SpannableStringBuilder(string), fromCharIndex, toCharIndex); } public static SpannableStringBuilder makeTextBold (Activity activity, SpannableStringBuilder string, int fromCharIndex, int toCharIndex) { SpannableStringBuilder sb = new SpannableStringBuilder(string); Typeface bold = Typeface.createFromAsset(activity.getAssets(), "fonts/NexaBold.ttf"); TypefaceSpan robotoBoldSpan = new CustomTypefaceSpan("", bold); sb.setSpan(robotoBoldSpan, fromCharIndex, toCharIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE); return sb; } public static SpannableStringBuilder colorText (int resourceId, String string, Activity activity, int fromCharIndex, int toCharIndex) { return colorText(resourceId, new SpannableStringBuilder(string), activity, fromCharIndex, toCharIndex); } public static SpannableStringBuilder colorText (int resourceId, SpannableStringBuilder sb, Activity activity, int fromCharIndex, int toCharIndex) { sb.setSpan(new ForegroundColorSpan(activity.getResources().getColor(resourceId)), fromCharIndex, toCharIndex, Spannable.SPAN_INCLUSIVE_INCLUSIVE); return sb; }
jobbert
source share