Using custom font for part of a Text

只谈情不闲聊 提交于 2019-12-10 10:15:53

问题


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.


回答1:


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




回答2:


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


来源:https://stackoverflow.com/questions/13227670/using-custom-font-for-part-of-a-text

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!