Roboto和Roboto Bold是否保证可以在4.0+上使用?

时间:2013-02-27 19:44:15

标签: android typeface

在我们的应用程序中,我们使用的是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 个答案:

答案 0 :(得分:3)

编辑:通过一些实验,尤其是允许用户更改字体的Galaxy S3,这就是我发现的:

  • 使用Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)将返回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中,系统字体将始终优先,并且列出的第一个系列是sans-serif,aria,helvetica,tahoma或verdana别名下的Roboto,除非我发现不然我认为可以安全地假设Roboto将是调用Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL)的返回字体。

我现在仍然要打开这个,希望得到一个明确的答案,因为我不确定是否允许OEM修改system_fonts.xml。如果是,那么这根本就没有用。

答案 1 :(得分:1)

Android 4.0 Compatibility Documentation的第3.8.5节中,它说:

  

3.8.5。主题Android提供“主题”作为应用程序在整个活动或应用程序中应用样式的机制。   Android 3.0引入了一个新的“Holo”或“全息”主题作为一套   为应用程序开发人员定义的样式,如果他们想匹配则使用   Android SDK定义的Holo主题外观[参考资料,   24。设备实现绝不能改变任何Holo主题   暴露给应用程序的属性[参考资料,25]。 Android 4.0   引入了一个新的“设备默认”主题作为一组定义的样式   应用程序开发人员如果想要匹配外观并使用它们   设备主题由设备实现者定义。设备   实现可以修改公开的DeviceDefault主题属性   到应用程序[参考资料,25]。

AFAIK,Roboto字体集是holo主题的一部分,因此必须出现在已通过Google认证的任何Android 4.0及以上设备上(即运行Google Play)。

4.14.2文件中也存在相同的要求

(在PDF中搜索Holo以快速查找该部分。仅提及4个部分)