Roboto font for Android 4+?

天涯浪子 提交于 2019-12-31 12:13:10

问题


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:)


回答1:


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.




回答2:


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




回答3:


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.




回答4:


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.



来源:https://stackoverflow.com/questions/19113420/roboto-font-for-android-4

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!