【问题标题】:Using CSS font-family to select Droid fonts not working on Android使用 CSS font-family 选择在 Android 上不起作用的 Droid 字体
【发布时间】:2011-07-01 23:17:29
【问题描述】:

我发现以下 HTML 代码在 Android 上不起作用(它只会使用默认字体:Droid Sans。在桌面上它按预期工作。

<p style='font-family: "Droid Sans",sans-serif;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "Droid Sans Mono",monospace;'>vând whisky și tequila, preț fix.</p>
<p style='font-family: "Droid Serif",serif;'>vând whisky și tequila, preț fix.</p>

【问题讨论】:

    标签: android fonts font-face font-family


    【解决方案1】:

    您的 css 中可能没有其他字体的 @font-face 声明。我想你只有一个 Droid Sans。每种字体都需要一个。例如,在你的 css 中你应该有:

    @font-face {
        font-family: 'DroidSans';
        src: url('font/DroidSans-webfont.eot?') format('eot'),
             url('font/DroidSans-webfont.woff') format('woff'),
             url('font/DroidSans-webfont.ttf') format('truetype'),
             url('font/DroidSans-webfont.svg#webfontw7zqO19G') format('svg');
        font-weight: normal;
        font-style: normal;
    
    }
    
    @font-face {
        font-family: 'DroidSansMono';
        src: url('font/DroidSans-Mono-webfont.eot?') format('eot'),
             url('font/DroidSans-Mono-webfont.woff') format('woff'),
             url('font/DroidSans-Mono-webfont.ttf') format('truetype'),
             url('font/DroidSans-Mono-webfont.svg#webfontSOhoM6aS') format('svg');
        font-weight: normal;
        font-style: normal;
    
    }
    
    @font-face {
        font-family: 'DroidSerif';
        src: url('font/DroidSerif-webfont.eot?') format('eot'),
             url('font/DroidSerif-webfont.woff') format('woff'),
             url('font/DroidSerif-webfont.ttf') format('truetype'),
             url('font/DroidSerif-webfont.svg#webfontw7zqO19G') format('svg');
        font-weight: normal;
        font-style: normal;
    
    }
    

    然后在您的代码中,您的 font-family 应该与您在上面的 css 中声明的那些相同(即 font-family: 'Droid Sans'; 与 font-family: 'DroidSans' 不同)

    <p style='font-family: "DroidSans",sans-serif;'>vând whisky și tequila, preț fix.</p>
    <p style='font-family: "DroidSansMono",monospace;'>vând whisky și tequila, preț fix.</p>
    <p style='font-family: "DroidSerif",serif;'>vând whisky și tequila, preț fix.</p>
    

    试试看,看看效果如何。

    【讨论】:

    • 顺便说一句,您还需要确保您在 css 中有正确的字体。在上面的示例中,所有字体文件都应该位于名为“fonts”的 css 子目录中。
    • 我没有尝试使用自定义字体,只使用浏览器提供的字体。
    • @tadywankenobi,Android 标签不存在,因为字体;)
    【解决方案2】:

    Android 似乎只能识别在system_fonts.xml 中定义的姓氏(fonts.xml 直到姜饼)。例如。要获得 Droid Serif,您应该编写通用的serif。详情请见this answer

    哦,“Droid Sans”有一个怪癖:自 4.0 以来,配置中就有一个 名称,但 .ttf 是 Roboto 的符号链接。

    我知道在 Android 的早期就有人说过“我们只会有 三种 字体,所以开发人员最好只使用通用名称,这样我们就可以随时替换它们" 推测>

    但这很不幸。您获得的实际字体可能不同的原因有很多:

    • 在 4.0 之前获得 Droid 系列,在获得 Roboto 系列之后。
    • Firefox 是 bundling Open Sans and Charis SIL 并使用它们来代替。
    • 制造商可能会用自己的字体替换这 3 种字体。编辑:我找不到任何确认这确实发生了。

    在所有这些情况下,如果我可以在我的字体堆栈中按实际名称引用特定字体,那就太好了。唉,我不能。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-05-11
      • 1970-01-01
      • 2016-10-12
      • 1970-01-01
      • 1970-01-01
      • 2015-03-28
      相关资源
      最近更新 更多