自定义字体的WebView [英] Custom font for webview

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

问题描述

我想建立一个新的自定义字体(OTF文件)对我的Web视图。

I am trying to establish a new custom font (otf file) for my web view.

我把资产文件anbaaarabic_bold.otf。

I put anbaaarabic_bold.otf in assets file.

还有就是我要做的:

String head = "<head><style>@font-face {font-family: 'verdana';src: url('file://"+ getActivity().getFilesDir().getAbsolutePath()+ "/anbaaarabic_bold.otf');}body {font-family: 'verdana';}</style></head>";
String htmlData= "<html>"+head+"<body style=\"font-family: verdana\">"+body+"</body></html>" ;

mBodyArticle.loadDataWithBaseURL("http://nada", htmlData,
                    "text/html", "utf-8", "");

体:包含我的HTML code

body : contain my html code.

我不知道为什么字体没有工作对我的web视图。体的html字体不改变。

I don't know why the font is not working for my webview. body html font doesn't change.

推荐答案

有一个的错误报告为Android,这似乎表明,自定义字体某些语言不工作(泰国语,希伯来语,波斯语,阿拉伯语已经提到)。这并没有得到证实由来自谷歌的人,但也有很多人报告了同样的问题。

There is a bug report for Android that seems to suggest that custom fonts don't work for certain languages (Thai, Hebrew, Farsi, and Arabic have been mentioned). This hasn't been confirmed by anyone from Google, but there are a number of people reporting the same problem.

一个建议的解决方案(其中至少一个用户确认作为工作)的是将字体从OTF到SVG转换。还有一些在线工具,会为你做这个(一切字体是一个例子),但你可能有问题本是一个受版权保护的字体 - 。请确保您的字体许可证允许这样的转换

One of the suggested solutions (which at least one user confirmed as working) was to convert the font from otf to svg. There are a number of online tools that will do this for you (Everything Fonts is one example), but you may have issues with this being a copyrighted font - make sure your font license permits such conversions.

此外,当您转换的字体,打开它在文本编辑器,并检查SVG元素是否命名空间。它应该是这个样子:

Also, when you have converted the font, open it up in a text editor and check whether the svg element is namespaced. It should look something like this:

<svg xmlns="http://www.w3.org/2000/svg">

如果它仅仅是&LT; SVG&GT; 没有命名空间,则可能需要添加的xmlns手动属性。显然,SVG字体没有命名空间都不能工作。

If it is just <svg> without the namespace, you may need to add the xmlns attribute manually. Apparently, svg fonts without the namespace don't work either.

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

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