Roboto font for Android 4+?-ThrowExceptions

Exception or error:

Do I need to use Roboto font and put it to asset folder if my app will support only Android 4+ devices?

I would greatly appreciate for your help. Alex. P.S. Sorry for my English:)

How to solve:

You can use Roboto natively from Android 4.1+ like this:

android:fontFamily="sans-serif"           // roboto regular
android:fontFamily="sans-serif-light"     // roboto light
android:fontFamily="sans-serif-condensed" // roboto condensed

For any version below that, you have to load the font yourself. Look at this answer I gave a while back for more information.

###

Answer

Ok. I think, I got it.

Samsung phones are by far the most popular Android phones. Whilst it’s
true that all Samsung phones from 4.1 and up have Roboto, they also
have something called Samsung Sans, and if your user has set it as
their default font then the android:font-family (as @Ahmad says)
requests all return Samsung Sans, not Roboto. If you have fixed tight
layouts with no wriggle-room that can’t stretch, Samsung Sans will
break them. There’s no easy way round this. If you absolutely have to
have Roboto, you must package it as an asset and set it as the
typeface explicitly.

Thx to @Ahmad as well as @Kenton Price’s comment here: https://stackoverflow.com/a/14633032/2553905

###

To add to Ahmad’s excellent answer, you can swap out ‘light’ or ‘condensed’ to whichever style it is you want from the list in the Material Design guidelines here:

http://www.google.com/design/spec/style/typography.html#typography-roboto-noto

For example:

android:fontFamily="sans-serif-medium"     // roboto medium

And so on.
This comment adds no more than Ahmad’s, but just clears up that you are not limited to the 3 examples he gave, you can use any.

###

From documentation:

Ice Cream Sandwich introduced a new type family named Roboto, created
specifically for the requirements of UI and high-resolution screens.

Read more about Typography.

Leave a Reply

Your email address will not be published. Required fields are marked *