如何在Phonegap和Android中使用网络字体?

14

PhoneGap支持Web字体吗?如果支持,如何使用它们?我在我的页面中有以下代码,但在模拟器中加载时无法正常工作(在Android应用程序内部,我尚未尝试通过浏览器加载页面)...

@font-face {
    font-family: 'HelveticrapRegular';
    src: url('fonts/helveticrap-webfont.eot');
    src: url('fonts/helveticrap-webfont.woff') format('woff'), url('fonts/helveticrap-webfont.ttf') format('truetype'), url('fonts/helveticrap-webfont.svg#webfontHlJ0Jib3') format('svg');
    font-weight: normal;
    font-style: normal;
}
body {
    font-family: "HelveticrapRegular", "Helvetica", "Arial", "sans serif";
}

在Firefox中,当我访问我的页面时,它可以正常工作,所以我不确定我做错了什么。

可能有帮助的是,字体CSS是由fontsquirrel生成的。

谢谢 :) Joel

3个回答

8

我在使用自定义Woff字体时遇到了问题。然后我将它从Woff格式转换为Ttf格式,这样它就可以在我的Android设备上正常工作了。因此,使用Woff格式可能存在问题。

因此,将.woff转换为.ttf可能会解决问题。


1
这种方法对我很有效。我使用了这个工具进行转换:http://orionevent.comxa.com/ - Mike McKay

5

我在使用PhoneGap时没有遇到识别web字体的问题。如果WebKit可以做到,那么Android和iOS也可以做到。 目前我正在进行的一个项目只在Android上进行了测试:

@font-face{
 font-family: MyFont; 
 src: url('../fonts/my_font.ttf') format('truetype');
 src: url('../fonts/my_font.otf') format('opentype');

然后按照样式进行排版。
font-family:MyFont, arial, sans-serif;

1

Webfonts在Android 2.1中存在问题,这是一个已知的错误,不幸的是。


@AdonisK。Web字体在Android 4.1上运行良好。我拥有一台4.1设备(Galaxy Note 2),并经常用于开发,其中我经常使用web字体。 - Phillip Elm
这是一个远程URL问题。 - Adonis K. Kakoulidis

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