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

kco*_*ock 5 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的设备使用自定义导入.

kco*_*ock 3

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

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

我发现一个名为的文档system_fonts.xml似乎确认 Roboto 将用于Typeface.SANS_SERIFSDK 目录中的任何引用:

平台 > 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>
Run Code Online (Sandbox Code Playgroud)

由于必须放置供应商字体fallback_fonts.xml并且系统字体将始终被优先考虑,并且列出的第一个系列是 Roboto,别名为 sans-serif、aria、helvetica、tahoma 或 verdana,除非我发现否则我认为它是安全的假设 Roboto 将是调用Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL).

我现在仍将对此保持开放状态,希望得到明确的答案,因为我不确定 OEM 是否可以修改 system_fonts.xml。如果是的话,那么这根本没有帮助。