Search code examples
androidfontstextviewmonospace

Monospace tabular numbers in Android TextViews


I have a custom font which has variable-width numeric glyphs by default, and I would like to use the font's monospace tabular numbers feature in an Android TextView so that numbers align vertically.

That is, change something like this:

to something like this:


Solution

  • To select a font's tabular number feature, use TextView's fontFeatureSettings with tnum:

    <TextView
        ...
        android:fontFeatureSettings="tnum"
        android:text="1111.11\n2222.22"
        />
    

    Requires API level 21.