[ACCEPTED]-Android Custom font Spannable Typeface Span-custom-font

Accepted answer
Score: 20

You are going to want to write a custom 2 TypefaceSpan. The good news is that they 1 aren't difficult. See here for an example.

Score: 0

You can do the following:

SpannableString spannableString = new SpannableString("your text");
Typeface typeface = Typeface.create(ResourcesCompat.getFont(this, R.font.your_font);
spannableString.setSpan(
    new TypefaceSpan(typeface, Typeface.NORMAL)), 
    0, 4, 
    Spanned.SPAN_EXCLUSIVE_EXCLUSIVE);

This constructor 3 will replace the previous style of the text, achieving 2 what you want. However, the catch is that 1 it was introduced in API 28.

More Related questions