我在一个TextView中使用两种不同的字体:第一种是SVG字体,第二种是TTF字体。
要将带有文本的图标设置为TextView,我正在使用它:
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);
结果:图标不在该行的垂直中心(或者文字不在垂直中心):