I know SpannableString is possible to set different text size in one textview but if textview is added programatically its 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);
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 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.
<View ... android:textAllCaps="false" />