自定义字体的WebView安卓 [英] custom font for webview android

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

问题描述

我在我的应用程序使用的WebView,我想在波斯语自定义字体显示的文字。我把我的字体在资源文件夹和写入地方文本的方法在web视图,但在api8是不支持波斯语。它dispaly未知字符,而不是我的文字和apies支持波斯语它不显示我的文字通过自定义字体,它显示我的文字默认字体。什么是错误的,我method.thanks 我的方法

 公共无效的setText(字符串文本)
{
    字符串蓝紫魅力=<风格类型= \文/ CSS \> @字体面{字体家庭:myface'; SRC:网址(文件:///android_asset/BYekan.ttf');}身体{字体家庭:myface';}< /风格>中;
    this.loadDataWithBaseURL(文件:///android_asset/BYekan.ttf,&LT; HTML DIR = \RTL \&GT;&LT; HEAD&GT;&LT;元含量= \text / html的;字符集= UTF-8 \ http-equiv=\"Content-Type\"/>"+style2+"</head><body>"+text+"</body></html>","text/html","UTF-8",null);
    setClickable(假);
    setLongClickable(假);
    setFocusable(假);
    setFocusableInTouchMode(假);
}
 

解决方案

您的风格应该是这个样子:

  @字体面{
字体家庭:myface;
字体重量:正常;
字体风格:正常;
SRC:网址(文件:///android_asset/BYekan.ttf')格式(TrueType字体);
}
 

I use a webview in my app and i want display text in farsi language with custom font .I place my font in asset folder and write a method for place text in webview but in api8 that dont support farsi language .it dispaly unknown characters instead of my text and in apies that support farsi language it dont display my text by custom font and it display my text by default font .what is wrong in my method.thanks my method

  public void setText(String text)
{
    String style2="<style type=\"text/css\">@font-face {font-family: 'myface';src: url('file:///android_asset/BYekan.ttf'); } body {font-family: 'myface';}</style>";
    this.loadDataWithBaseURL("file:///android_asset/BYekan.ttf","<html  dir=\"rtl\"><head><meta content=\"text/html; charset=utf-8\" http-equiv=\"Content-Type\"/>"+style2+"</head><body>"+text+"</body></html>","text/html","UTF-8",null);
    setClickable(false);
    setLongClickable(false);
    setFocusable(false);
    setFocusableInTouchMode(false);
}

解决方案

Your style should look something like this:

@font-face{ 
font-family:myface;
font-weight:normal;
font-style:normal;
src:url('file:///android_asset/BYekan.ttf') format('truetype');
}

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

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