如何在 WebView 中使用自定义字体 [英] How to use custom font with WebView

查看:44
本文介绍了如何在 WebView 中使用自定义字体的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在我想显示一些unicode字符并且我使用了标签:<font face="Arial">something here</font>.但是似乎WebView找不到Arial字体,因为我只能看到 UFO 字符.我是否必须将 arial.ttf 复制到某处或如何将这种 TrueType 字体与 WebView 一起使用?谢谢.

Now I want to display some unicode characters and I have used tag: <font face=" Arial">something here</font>. But it seems that WebView can not find the Arial font because I can only see UFO-characters. Do I have to copy arial.ttf to somewhere or how can I use this TrueType font with WebView? Thanks.

推荐答案

loadData 对我也不起作用,所以我使用了 file:///android_assetsrc 路径.

loadData didn't work for me either, so I used file:///android_asset in the src path.

它与 loadDataWithBaseURL 一起工作!

在本例中,我将 CSS 更改为:

For this example I changed the CSS to:

@font-face {
    font-family: 'feast';
    src: url('fonts/feasfbrg.ttf');
}

body {font-family: 'feast';}

然后使用资产路径作为基本网址:

Then use the assets path as the base url:

loadDataWithBaseURL("file:///android_asset/",myhtml,"text/html","utf-8",null);

这篇关于如何在 WebView 中使用自定义字体的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆