我的应用程序中有一个Webview,其中的正文文本需要使用“ Times New Roman”字体呈现。首先,我将.ttf文件放在我的Assets文件夹中。
我已经将我的style.css文件修改为以下内容:
@font-face {
font-family: "Times New Roman";
src: url("Times-New-Roman.ttf");
}
#body{
font-family: "Times New Roman",Arial,sans-serif;
font-weight: normal;
font-size: 8px;
}
我这样创建我的WebView:
WebView webView = new WebView(activity.getApplicationContext());
String child = "<html><head><link rel=\"stylesheet\" type=\"text/css\" href=\"style.css\"><body>Test</body></html>";
webView.loadDataWithBaseURL("file:///android_asset/", child, "text/html", "UTF-8", null);
return webView;
但是,当WebView呈现为默认的Android字体而不是Times New Roman时,仍然如此。我不知道这是否重要,但我将字体从我的/ Library / Fonts文件夹复制到了MacBook上,并使用“-”表示空格将其重命名。
我想到了。通过在CSS中删除body之前的#,我可以使用它。如果比我更了解HTML的人看到了这一点,那么请您说明一下为什么这样做有效?
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句