Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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:

like image 294
laalto Avatar asked Dec 14 '16 13:12

laalto


1 Answers

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.

like image 200
laalto Avatar answered Oct 24 '22 09:10

laalto