Roboto和Roboto Bold是否保证在Android 4.0及以上版本中可用?

5
在我们的应用程序中,我们使用Roboto和Roboto Bold字体。然而,在某些Android版本中(似乎是4.0到4.1),当使用导入版本的Roboto(即使用Typeface.createFromAsset())时,我们遇到了文本渲染问题,但是如果只是使用内置版本的Roboto(即Typeface.DEFAULT),则不会出现这些问题。
我知道Roboto和Roboto Bold是在Android 4.0中引入的,但似乎找不到任何保证这些字体无论制造商如何修改(例如Touchwiz、Sense)都可用的内容。如果它们有保证存在,那么我们可以使用版本检查来仅对低于Android 4.0的设备使用自定义导入。
2个回答

3

编辑:通过一些实验,特别是使用可以更改字体的Galaxy S3,我发现以下内容:

  • 使用Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)将返回自定义字体,而不是系统默认的sans-serif字体(即Roboto)
  • 相反,使用Typeface.create("sans-serif", Typeface.NORMAL)(或BOLD),它将返回Roboto,无论用户的字体定制如何。从下面的列表中,你实际上可以使用“helvetica”、“tahoma”、“verdana”或“arial”代替“sans-serif”,结果相同。

我找到了一个名为system_fonts.xml的文档,似乎确认在SDK目录下引用Typeface.SANS_SERIF时将使用Roboto,该文件位于以下位置:

平台 > 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,别名为sans-serif、aria、helvetica、tahoma或verdana,除非我有其他发现,否则我认为可以安全地假定调用“Typeface.create(Typeface.SANS_SERIF,Typeface.NORMAL)”将返回Roboto字体。

目前仍然保持开放状态,希望得到明确的答案,因为我不确定OEM是否被允许修改system_fonts.xml。如果允许,那么这并没有真正提供帮助。


1
Android 4.0兼容性文档的第3.8.5节中,它说:
"Android提供了“主题”作为应用程序在整个Activity或应用程序中应用样式的机制。Android 3.0引入了一个新的“Holo”或“全息”的主题,作为应用程序开发人员使用的一组定义的样式,如果他们想要匹配由Android SDK [资源,24]定义的Holo主题的外观和感觉,设备实现不得改变任何暴露给应用程序的Holo主题属性[资源,25]。 Android 4.0推出了一个新的“设备默认”主题,作为应用程序开发人员使用的一组定义的样式,如果他们想要匹配由设备实现者定义的设备主题的外观和感觉。设备实现可以修改向应用程序公开的DeviceDefault主题属性[Resources,25]。"
据我所知,Roboto字体集是Holo主题的一部分,因此必须在任何已由Google认证(即运行Google Play)的Android 4.0及以上设备上存在。

同样的要求也出现在4.14.2文档中。

(在PDF中搜索Holo以快速找到该部分。只有4次提及)


我不是完全确定,但我认为默认的Holo主题没有指定字体,只有文本大小和样式,这将允许制造商选择要使用的字体。 - ebarrenechea
@ebarrenchea 就算我也不确定,而且我找不到官方文档或兼容性文件中确认或否认这一点的地方,这就是为什么我选择说 AFAIK 的原因。 - Raghav Sood
1
我刚在Google+上联系了Adam Powell(撰写了这篇文章),以便他能够澄清。 - Kevin Coppock
@kcoppock请告诉我们他说了什么! - Raghav Sood
1
如果他回复的话,我一定会去做的。 :) - Kevin Coppock

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接