Question

I have the string <string name="getStarted">Get Started!</string>.

I have set it's textview to android:fontFamily="sans-serif-light".

Can I have the Started! as a regular fontFamily where the rest of the string (Get) having a light weight?

I tried: <string name="getStarted">Get <n>Started!</n></string> like <b></b> but well... n is not a tag (n for normal).

Was it helpful?

Solution 2

For consistency, based on @Gavin2058 's answer.

SpannableString sb = new SpannableString("Get Started!");
sb.setSpan(new TypefaceSpan("sans-serif"), 4, 11, Spannable.SPAN_EXCLUSIVE_INCLUSIVE);
yourTextView.setText(sb); 

SPAN_EXCLUSIVE_INCLUSIVE helps you add more setSpan of the same style if you have a big string with multiple width words.

OTHER TIPS

final SpannableStringBuilder sb = new SpannableStringBuilder("Get Started!");  
final StyleSpan bss = new StyleSpan(android.graphics.Typeface.BOLD); // Span to make text bold  
sb.setSpan(bss, 4, 11, Spannable.SPAN_INCLUSIVE_INCLUSIVE); // make them also bold 
yourTextView.setText(sb); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top