Search code examples
androidfontsspannablestring

Using custom font for part of a Text


Typeface robotoBold = Typeface.createFromAsset(activity.getAssets(),
        "fonts/Roboto-Bold.ttf");
Typeface robotoLight = Typeface.createFromAsset(activity.getAssets(),
        "fonts/Roboto-Light.ttf");


SpannableStringBuilder sb = new SpannableStringBuilder("This must be BOLd\nThis must be NORMAL");
sb.setSpan(robotoBold, 0, 17, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
sb.setSpan(robotoLight, 18, 37, Spannable.SPAN_INCLUSIVE_INCLUSIVE);
mTextView.setText(sb);

This gives me a normal text for the whole TextView.

Thank You.


Solution

  • We are able to do this functionality

    font for part of a Text

    you have to use alter net like take two textview and divide your text and set that text.

    or use

    spannable text