【发布时间】:2016-06-03 16:45:26
【问题描述】:
我想在我的 WebView 中插入字体,以便在不同的网站上显示一些特殊字体。
例如,在 Wikipedia 中,我希望我使用一些代码来更改 html 中的字体,完成后,我显示的页面和字体不像 html 代码中的 Century Gothic。当我尝试使用 Google Chrome 时也无法正常工作。当我尝试:
webView.loadDataWithBaseURL(...)
如果我放在标题上它会起作用:
"<link rel='stylesheet' type='text/css' href='file:///android_asset/style.css'/>"
在我的 style.css 中:
@font-face {
font-family: Andika;
src: url('fonts/Andika.ttf');
}
@font-face {
font-family: Calibri;
src: url('fonts/Calibri.ttf');
}
@font-face {
font-family: Century Gothic;
src: url('fonts/CenturyGothic.ttf');
}
@font-face {
font-family: Comic Sans MS;
src: url('fonts/ComicSansMS.ttf');
}
@font-face {
font-family: Lexia;
src: url('fonts/Lexia.ttf');
}
@font-face {
font-family: Lucida Sans Unicode;
src: url('fonts/LucidaSansUnicode.ttf');
}
@font-face {
font-family: Tahoma;
src: url('fonts/Tahoma.ttf');
}
@font-face {
font-family: Tiresias;
src: url('fonts/Tiresias.ttf');
}
@font-face {
font-family: Trebuchet MS;
src: url('fonts/TrebuchetMS.ttf');
}
@font-face {
font-family: Verdana;
src: url('fonts/Verdana.ttf');
}
但它是在本地数据上。
我想用维基百科这样的外部页面来实现。
当我在维基百科 html 页面上注入链接时,我收到以下错误消息:
Not allowed to load local resource: file:///android_asset/
如果我直接将@font-face 放在样式字段中,我也会遇到同样的错误。
有人有解决这个错误的想法吗?
请!
谢谢
【问题讨论】:
标签: android html css webview fonts