android - 在android中以自定义字体显示webview的html内容
问题描述
我在 web 视图中显示了下面的 HTML 内容
<p><a href="https://www.google.com"><cite>Here</cite></a></p>
如何应用.ttf file
我在资产文件夹中的自定义字体()
解决方案
尝试这样做:
WebView webview = findViewById(R.id.webView1);
String start = "<html><head><style type=\"text/css\">@font-face {font-family: MyFont;src: url(\"YOUR CUSTOM FONT ASSET HERE")}body {font-family: MyFont;font-size: medium;text-align: justify;}</style></head><body>";
String end = "</body></html>";
String mHtmlString = start + "<p><a href="https://www.google.com"><cite>Here</cite></a></p>" + end;
webview.loadDataWithBaseURL(null,mHtmlString, "text/html", "UTF-8", null);
推荐阅读
- javascript - 我将如何编写一个函数来返回等于目标总和 WITH RECURSION 的 3 个数字的所有组合
- google-app-engine - 如何通过 app.yaml 将环境变量传递给谷歌应用引擎?
- java - 如何在Java中找到列表的偶数
- r - 你怎么说`[`和`[[`?
- java - 如何创建具有相同超类的多个类型的列表,而不会丢失类型
- javascript - 如何将 Cropper.js 与已经上传到我的服务器的图像一起使用,而不是裁剪然后将图像上传到正确的文件夹
- javascript - 为什么我在 discord.js 中使用此 Slash 命令时收到错误“无效的交互应用程序命令”?
- haskell - 如何获取 Haskell 代码字符串(连同值)
- java - flink-connector-redis 中如何设置 TTL 使 Redis 的 key 过期?
- html - 我正在尝试在 div 中制作响应式图像