2013-02-27 23 views
5

在我們的應用程序中,我們使用Roboto和Roboto Bold。但是,在Android中的某些版本(好像是4.0〜4.1),我們有文本渲染問題使用的Roboto的進口版本時(即使用Typeface.createFromAsset()),只需使用內置的Roboto的版本(即Typeface.DEFAULT時不出現)。Roboto和Roboto Bold是否保證在4.0+上可用?

我知道Roboto和Roboto Bold是在Android 4.0中引入的,但我似乎無法找到任何可以保證這些字體可用的東西,無論製造商修改如何(例如Touchwiz,Sense)。如果它們保證存在,我們可以使用版本檢查來僅使用低於Android 4.0的設備的自定義導入。

回答

3

編輯:對於某些實驗,特別是與允許用戶改變他們的字體的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。如果是,那麼這根本就沒有什麼幫助。

1

Android 4.0 Compatibility Documentation的第3.8.5節,它說:

3.8.5。主題Android提供「主題」作爲應用程序在整個活動或應用程序中應用樣式的機制。 Android 3.0引入了一個新的「Holo」或「全息」主題,作爲一組 定義的樣式,供應用程序開發人員使用,如果他們想要匹配 Android SDK定義的Holo主題外觀[Resources, 24] 。設備實現不得改變暴露的應用[資源,25]任何河洛主題 屬性。 Android 4.0的 引入了一個新的「設備默認」的主題爲 應用開發的一套定義的樣式,如果他們想匹配的外觀和感覺的裝置主題的 由設備實現定義使用。設備 實現可以修改暴露 到應用[資源,25] DeviceDefault主題屬性。

AFAIK,Roboto字體集是holo主題的一部分,因此需要出現在任何已通過Google認證的Android 4.0及更高版本設備上(即運行Google Play)。

同樣的要求也存在於4.14.2文件

(搜索霍洛在PDF文件中快速找到節僅4中提到的它有。)

+0

我對此並不完全確定,但我認爲默認的Holo主題沒有指定字體,只有文字大小和樣式可以讓製造商選擇使用哪種字體。 – ebarrenechea 2013-02-27 19:59:35

+0

@ebarrenchea即使我不確定,也無法在文檔或兼容性文檔中找到證實或否認這一點的官方位置,這就是爲什麼我選擇說'AFAIK' – 2013-02-27 20:00:28

+1

我剛剛與Adam Powell(誰寫了[這篇文章](http://android-developers.blogspot.com/2012/01/holo-everywhere.html))在Google+上,看看他是否可以澄清。 – kcoppock 2013-02-27 20:04:28