2

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?

BArtWell
  • 4,176
  • 10
  • 63
  • 106

2 Answers2

7

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

Pavlo Ostasha
  • 14,527
  • 11
  • 35
  • In code, that's `text1.typeface = resources.getFont(R.font.Aller_Display)` and `text1.fontFeatureSettings = "smcp"`, right? – Cliabhach Feb 04 '20 at 10:45
0

As you are using TextView so I guess you set value to it at runtime like says you have some String object which will get set to the TextView like:

textView.setText(someStringObj);

So you can easily set it as in lower case on it by adding:

textView.setText(someStringObj.toLowerCase());
Harpreet
  • 2,990
  • 3
  • 38
  • 52
  • @PaulOst but in my case it get worked. It turns out it works only with lower cased strings. – BArtWell Feb 04 '20 at 13:57
  • @BArtWell So you problem was that you tried to use Small Caps but entered Upper Case Text - I just could not have though that this may be the problem. I thought you know how Small Caps works. I will add this clarification to my answer... – Pavlo Ostasha Feb 04 '20 at 14:01
  • @PaulOst yes, it was also specified in sample code. – BArtWell Feb 04 '20 at 14:05
  • @BArtWell sorry - didn't see it - my bad. – Pavlo Ostasha Feb 04 '20 at 14:33
  • @PaulOst, Yᴇs I ɢᴏᴛ ᴛʜᴀᴛ ᴛʜᴇ ᴏ̨ᴜᴇsᴛɪᴏɴ ɴᴇᴇᴅ ᴛᴇxᴛ ɪɴ ᴛʜɪs ᴛʏᴘᴇ ᴏғ ғᴏʀᴍᴀᴛ ʙᴜᴛ ᴍᴀɪɴ ᴄᴀᴜsᴇ ɪs ᴛʜᴀᴛ ᴛʜᴇ TEXT ʜᴀs ᴛᴏ ɪɴ LᴏᴡᴇʀCᴀsᴇ ᴛᴏ ғɪʟʟ ɪɴ ᴡɪᴛʜ ᴛʜᴀᴛ ᴘʀᴏᴘᴇʀᴛʏ. – Harpreet Feb 05 '20 at 07:01