The CommonsBlog

Think About Font Scale

For years, sp was the guest nobody wanted at the dimension unit party. While we were told that sp units would scale with the font scale, users and developers had no good means of affecting the font scale. As a result, many developers skipped sp in favor of other units for text sizes, simply because they understood the other units better.

However, for the past year, we have had users capable of changing font scale. Android 4.0 added a “Font size” option to the Settings app (in stock Android, you will see this under the “Display” header), allowing users to switch between a few pre-defined scales (small, normal, large, huge).

For text sizes specified in sp, the actual size scales based upon this font size selection. So while 1sp == 1dp for “normal” scale fonts, 1sp > 1dp for “large” and “huge” scale fonts, and 1sp < 1dp for “small” scale fonts.

By contrast, text sizes in other units of measure, like dp, are unaffected by this.

Of course, the knee-jerk reaction of many developers will be to rip out any sp units they might have and replace them with dp, since they cannot control the absolute size of sp units. That would be a mistake. Just as users of desktop Web browsers may adjust font scale to make sites more readable, users of mobile devices might adjust the system font scale to make apps more readable. Freezing your text sizes using dp simply means that your app will be out of step with other apps, notably the system-supplied apps. And, since the user is asking for the different-sized fonts, the user may be disappointed if your app ignores the request.

Testing font scale is “another one of those things” to add to your testing list, along with testing on different densities, testing different langauges (to ensure strings do not run too long), and so on.

Need an Android programming guide for your development team? An Enterprise Warescription to The Busy Coder’s Guide to Android Development is available for teams of 10+ members. Contact Mark Murphy for details.