HarmonyOS 通过webview改变H5页面字体?

如题:HarmonyOS 通过webview改变H5页面字体?

阅读 586
1 个回答

可以将字体文件放在工程rawfile目录下,在H5代码中使用@font-face指定用于显示文本的自定义字体,在指定元素中配置font-family属性设置自定义字体。 示例代码:

webFixedFont<!DOCTYPE html>
  <html lang="en">
  <head>
  <meta charset="UTF-8" />
  <meta http-equiv="X-UA-Compatible" content="IE=edge" />
  <meta name="viewport" content="width=device-width, initial-scale=1.0" />
  <title>Document</title>
  <style>
@font-face {
  font-family: 'MaoKenWangXingYuan';
  src: url('./MaoKenWangXingYuan.ttf');
}
#title {
  font-family: 'MaoKenWangXingYuan';
}
</style>
  </head>
  <body>
  <h1 id="title">猫啃忘形圆</h1>
  </body>
  </html>