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

时间:2013-01-06 05:49:25

标签: android android-layout android-webview android-fonts

我正在生成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);

但仍然没有加载,没有得到我错过的东西?

编辑:

我正在关注日志,只有这五行。

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

编辑:我认为以上日志与问题无关“特别是”错误打开跟踪文件:“每当我运行任何应用程序时它都会出现。

1 个答案:

答案 0 :(得分:0)

你检查过这个字体的错吗?我和MyriadPro-Regular.otf有类似的问题,其他字体在那里工作正常。