6

I'm using two different fonts in one TextView: first is SVG font , second TTF font.

To set icon with text to TextView I'm using this:

        String icon =getContext().getString(iconId);//""
        String text = getResources().getString(labelId);//"AnyText"

        int iconLength = icon.length();
        String fulltext = icon + " " + text;
        SpannableStringBuilder spLabelWithIcon = new SpannableStringBuilder(fulltext);
        spLabelWithIcon.setSpan(new CustomTypefaceSpan(TypefaceManager.ICONS.getTypeface()),
                0, iconLength, Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

        spLabelWithIcon.setSpan(new CustomTypefaceSpan(TypefaceManager.GOTHAM_BOOK.getTypeface()),
                iconLength, fulltext.length(), Spanned.SPAN_EXCLUSIVE_INCLUSIVE);

myTextView.setText(spLabelWithIcon);

Result: the icon is not on vertical center of the line(or maybe text is not on vertical center):

enter image description here

Paul LeBeau
  • 97,474
  • 9
  • 154
  • 181
NickUnuchek
  • 11,794
  • 12
  • 98
  • 138

0 Answers0