如何在 HTML 中使用自定义的字体?

我实时生成HTML 页面,我想把字体文件放进assets 文件夹中 ,"MyriadProRegular.otf"。

String mStyle = "<style type=\"text/css\"> body { font-size: 100%; font-family: 'MyriadProRegular'; src: url('file:///android_asset/MyriadProRegular.otf'); }  </style>";
String mHTML = "<html><head> " + mStyle + " </head><body>"
    + " Hello World " + "</body></html>";

加载方法:

WebView mWebview = new WebView(this);
mWebview.loadDataWithBaseURL(null, mHTML, "text/html","utf-8", null);

HTML没有加载上字体
我用这个代码试了试:

body { font-size: 100%; font-family: 'MyriadProRegular'; src:url('MyriadProRegular.otf'); } 

和:

mWebview.loadDataWithBaseURL("file:///android_asset/", mHTML, "text/html","utf-8", null);

但是还是没有加载上去,我该怎么改呢?
log 信息:

04-26 11:39:34.724: E/Trace(2090): error opening trace file: No such file or directory (2)
04-26 11:39:35.923: D/dalvikvm(2090): GC_CONCURRENT freed 53K, 3% free 8410K/8583K, paused 40ms+28ms, total 216ms
04-26 11:39:36.253: I/Choreographer(2090): Skipped 56 frames!  The application may be doing too much work on its main thread.
04-26 11:39:36.293: D/gralloc_goldfish(2090): Emulator without GPU emulation detected.
04-26 11:39:36.794: I/Choreographer(2090): Skipped 80 frames!  The application may be doing too much work on its main thread.

PS: 我不知道这个 log 信息与问题有关系没,特别是 " error opening trace file:" 这句话,当我每次运行程序的时候都出现。

查看全部
znl_12
znl_12
2013/04/28 09:56
  • layout
  • webview
  • fonts
  • android
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

1个回复