1

将自定义字体设置为 html 页面并使用 loadDataWithBaseURL 加载 html 数据时,会忽略粗体标记。我的代码如下:

webView.loadDataWithBaseURL("", "<html><style type=\"text/css\"> @font-face { font-family:\"customFont\"; src:url('file:///android_asset/fonts/customfont.ttf');line-height:45px;font-size:34px;}  body { font-family:'customFont'; }</style><body><b>The legend is back!!</b></body></html>", "text/html", "utf-8", "");

我的输出如下所示:

当使用 loadData 加载相同的内容时,如下所示:

 webView.loadData("", "<html><style type=\"text/css\"> @font-face { font-family:\"customFont\"; src:url('file:///android_asset/fonts/customfont.ttf');line-height:45px;font-size:34px;}  body { font-family:'customFont'; }</style><body><b>The legend is back!!</b></body></html>", "text/html", "utf-8", "");

我的输出如下所示:

在此处输入图像描述

不确定可能的问题是什么。有没有相同的具体原因。

4

1 回答 1

2

现在我通过使用粗体字体并在我的 html 中使用 css 指定相同的字体解决了这个问题。我的CSS代码如下:

@font-face {font-family: MyArialBold;src: url('file:///android_asset/fonts/ArialBold.ttf')} b{font-family: ArialFontBold;}.

希望有帮助。

于 2013-06-28T03:39:05.873 回答