我们在Android应用中使用自定义阿拉伯字体。我们使用@ font-face来指定使用SVG和TrueType字体文件的字体。默认情况下,WebView加载SVG字体,我们注意到字体的SVG版本缺少某些字符。有没有什么办法可以强制Webview只使用TrueType(ttf)字体而不是SVG。
答案 0 :(得分:0)
试试这段代码:
webSettings.setFixedFontFamily("file:///android_asset/myfont.ttf");
答案 1 :(得分:0)
就像这样,它完美无缺。
1 //load the fontType
private String getHtmlData(String bodyHTML) {
String head = "<head>" +
"<meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"> " +
"<style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"file:///android_asset/fonts/myfont.TTF\")}body {font-family: MyFont;font-size: medium;text-align: justify;}</style>"+
"</head>";
return "<html>" + head + "<body>" + bodyHTML + "</body></html>";
}
2 // load the webview content
webView.loadDataWithBaseURL(null, getHtmlData(content), "text/html", "utf-8", null);
3 // end.