Nic*_*hek 5 android text spannable
我在一个 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);
Run Code Online (Sandbox Code Playgroud)
结果:图标不在行的垂直中心(或者文本不在垂直中心):