我實時生成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:" 這句話,當我每次運行程序的時候都出現。
@font-face {
font-family: 'myface';
src: url('file:///android_asset/fonts/myfont.ttf');
}
body {
font-family: 'myface', serif;
試一下這樣調用,能不能運行不太清楚 --!
那個錯誤提示不關緊要,不是版本不統一問題就是xml文件問題
不影響運行就行