将资源中的字体系列动态加载到 WebView 中

load font family from Assests into WebView dinamically

我的应用程序的 assets 目录中有一些 ttf 文件,例如 AdobeArabic-Regular.ttf。现在我想 运行 这个 javascript 代码在 WebView:

object.style.fontFamily = "AdobeArabic-Regular";

但我不知道如何动态加载该字体?由于 font family 会动态变化,所以使用 this described way 并不能解决我的问题。

您需要将 CSS 注入 webview 这 很有帮助

并在CSS

中设置字体
body {
  font-family: "Times New Roman", Times, serif;
}