I need to show SmallCaps text in TextView. I am trying to use code below:
<TextView
android:id="@+id/text1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:fontFeatureSettings="smcp"
android:textColor="@color/black"
android:textSize="16sp"
android:text="TEXT" />
But it just shows me normal text, without SmallCaps effect. I also try to set it programmatically (text1.fontFeatureSettings = "smcp"
) but also without success.
How to make SmallCaps text in Android? Why fontFeatureSettings doesn't work?
In order for this feature to work you have to have a font that actually has Small Caps characters - thus to make it work pass the font with Small Caps via app:fontFamily(android:fontFamily)
for example Aller Display
, and then use android:fontFeatureSettings="smcp"
to make it Small Caps.
Hope it helps
Edit
as @Cliabhach pointed in comments, in code it will look something like
text1.typeface = resources.getFont(R.font.Aller_Display)
text1.fontFeatureSettings = "smcp"
Edit2
Keep in mind For those who do not know - Small Caps will only work on lowercase characters