I know SpannableString is possible to set different text size in one textview but if textview is added programmatically it's not working.
String s = "Best Ever";
SpannableString ss1 = new SpannableString(s);
ss1.setSpan(new RelativeSizeSpan(2f), 0, 4, 0); // set size
ss1.setSpan(new ForegroundColorSpan(Color.RED), 0, 4, 0); // set color
TextView tv = (TextView) findViewById(R.id.textview);
tv.setText(ss1);
As you can see, It's work on Button and TextView for API17 but work on TextView only on API21
Interesting! I notice that the button on API 21 is all caps..So remove all caps.
By default, Material buttons are styled to show text in all-caps. However, there is a bug in the AllCapsTransformationMethod ( bug details )used for capitalization that causes it to discard Spannable data.
You can override the default button styling by disabling allCaps mode, which is true by default for Material-styled widgets.
From code,
txt.setAllCaps(false);
From XML,
<View
...
android:textAllCaps="false" />
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With