34

When setting custom fonts for a textview, I can only choose normal, bold or italic: enter image description here

How can I set the style to be light instead of bold in the following example?

<TextViewWithCustomFont
...
android:textStyle="bold"/>
AlikElzin-kilaka
  • 34,335
  • 35
  • 194
  • 277
  • Use a combination of them e.g. `android:textStyle="normal|bold|italic"` or `android:textStyle="normal|bold"`, you have more than 10 combinations. – g00dy Aug 14 '13 at 13:48
  • 3
    @g00dy there are only 4 combinations. `normal` , `bold`, `italic` and `bold|italic`. In code this is `Typeface.BOLD`, `Typeface.ITALIC`, `Typeface.BOLD_ITALIC` and `Typeface.NORMAL`. Because these are Integers and bold being 1 and italic being 2 and bolditalic being 3 then `Typeface.ITALIC|Typeface.BOLD == Typeface.BOLD_ITALIC` – Ivo Aug 14 '13 at 14:03
  • @g00dy, `android:textStyle="normal|bold"` just give a bold??? – Sam Dec 23 '17 at 10:25

3 Answers3

71

This is font specific. Not all fonts have a light, medium, thin attribute/style, but the default font should. You can use the default light font by using fontFamily: sans-serif-light or for thin, fontFamily: sans-serif-thin.

For custom fonts, you would need to include the light version of the font and use it.

Alex Fu
  • 5,509
  • 3
  • 31
  • 40
  • 1
    how about for semi-bold? – Sam Dec 23 '17 at 10:22
  • @Sam: use android:fontFamily="@font/robotomedium" (or "sans-serif-medium") but remember to remove android:textStyle="bold" (these two attributes are not exclusive) – smukamuka Mar 30 '21 at 11:21
-1

Letter Spacing

As an adjacent solution to change a font's looks, you could use letterSpacing. This will change the distance between the letters within a TextView.

A positive number like 0.2 will add more of a gap, while negative like -0.1 will squish the letters together.

In Android 21+ you can programmatically call setLetterSpacing or in XML add letterSpacing.

Gibolt
  • 42,564
  • 15
  • 187
  • 127
-3

You can only combine those three attributes :

  • normal
  • bold
  • italic

http://developer.android.com/reference/android/widget/TextView.html#attr_android:textStyle

So it can be :

  • normal
  • bold
  • italic
  • bold | italic
Rémi F
  • 1,327
  • 12
  • 25
  • 4
    I know what it can be. I'm asking how to set other styles for custom fonts that have other styles. – AlikElzin-kilaka Aug 14 '13 at 14:26
  • 3
    @kilaka: "I'm asking how to set other styles for custom fonts that have other styles" -- Android does not support such a concept, unless those "other styles" are split out into separate font files, loaded individually. – CommonsWare Aug 14 '13 at 15:03
  • @CommonsWare - If the font files are loaded individually, there's no meaning to `style` - just the typeface. This means that the style attribute is useless in custom fonts. – AlikElzin-kilaka Aug 14 '13 at 15:10
  • @CommonsWare - thanks. I conclude that there is no custom typeface **family** - just a specific font. This is strange. Why have built in families but no support for custom families? – AlikElzin-kilaka Aug 15 '13 at 09:05