編輯:對於某些實驗,特別是與允許用戶改變他們的字體的Galaxy S3,這是我發現的:
- 使用
Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)
將返回th在CUSTOM字體,而不是系統默認的sans-serif字體(即的Roboto)
- 相反,使用
Typeface.create("sans-serif", Typeface.NORMAL)
(或BOLD),它將返回的Roboto無論用戶的字體自定義的。從下面的列表中,您可以使用上面的「helvetica」,「tahoma」,「verdana」或「arial」而不是「sans-serif」來獲得相同的結果。
我發現了一個名爲system_fonts.xml
文件,似乎證實的Roboto將在SDK目錄下用於任何參考Typeface.SANS_SERIF
:
平臺> Android的14>數據>字體
<!--
System Fonts
This file lists the font families that will be used by default for all supported glyphs.
Each entry consists of a family, various names that are supported by that family, and
up to four font files. The font files are listed in the order of the styles which they
support: regular, bold, italic and bold-italic. If less than four styles are listed, then
the styles with no associated font file will be supported by the other font files listed.
The first family is also the default font, which handles font request that have not specified
specific font names.
Any glyph that is not handled by the system fonts will cause a search of the fallback fonts.
The default fallback fonts are specified in the file /system/etc/fallback_fonts.xml, and there
is an optional file which may be supplied by vendors to specify other fallback fonts to use
in /vendor/etc/fallback_fonts.xml.
-->
<familyset>
<family>
<nameset>
<name>sans-serif</name>
<name>arial</name>
<name>helvetica</name>
<name>tahoma</name>
<name>verdana</name>
</nameset>
<fileset>
<file>Roboto-Regular.ttf</file>
<file>Roboto-Bold.ttf</file>
<file>Roboto-Italic.ttf</file>
<file>Roboto-BoldItalic.ttf</file>
</fileset>
</family>
由於供應商的字體必須放置在fallback_fonts.xml
和系統字體將始終優先,列出的第一個家族是Roboto下的無襯線,詠歎調,黑體,塔霍瑪,或verdana別名,除非我發現否則我認爲這是安全的假設Roboto將是返回的字體爲Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)
。
我仍然打算暫時打開此文件,希望得到明確的答案,因爲我不確定是否允許OEM修改system_fonts.xml。如果是,那麼這根本就沒有什麼幫助。
我對此並不完全確定,但我認爲默認的Holo主題沒有指定字體,只有文字大小和樣式可以讓製造商選擇使用哪種字體。 – ebarrenechea 2013-02-27 19:59:35
@ebarrenchea即使我不確定,也無法在文檔或兼容性文檔中找到證實或否認這一點的官方位置,這就是爲什麼我選擇說'AFAIK' – 2013-02-27 20:00:28
我剛剛與Adam Powell(誰寫了[這篇文章](http://android-developers.blogspot.com/2012/01/holo-everywhere.html))在Google+上,看看他是否可以澄清。 – kcoppock 2013-02-27 20:04:28