android - Android webView 中的阿拉伯语自定义字体

标签 android webview fonts

我正在尝试向 webView 添加阿拉伯语自定义字体,但没有成功。在我的例子中,webView 呈现设备附带的默认字体。

我试过 ttf 和 otf 字体类型也通过 https://everythingfonts.com 将字体类型转换为 svg|没有运气

这是我的代码:

存放在assets文件夹中的html文件:

 <html>
<head>
    <meta http-equiv="content-type" content="text/html;" charset="UTF-8">
    <style>
        /** Specify a font named "MyFont",
        and specify the URL where it can be found: */
        @font-face {
        font-family: "MyFont";
        src: url('file:///android_asset/fonts/NotoKufiArabic-Bold.ttf') format(‘truetype’); ;
        }
        h3 { font-family:"MyFont"}
    </style>
</head>
<body>
<h3>
مرحبا</h3>
</body>
</html>

我调用 webView 的 MainActivity:

 public class MainActivity extends Activity {

    WebView mWebView;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        // Getting reference to WebView of the activity_main layout
        mWebView = (WebView) findViewById(R.id.webview);

        // Loading an html page into webview
        mWebView.loadUrl("file:///android_asset/demo.html");
    }
 ...........
 ...........

我的代码在英文文本和字体的情况下工作正常,但在阿拉伯语中没有任何效果。

最佳答案

使用 <h3 dir="rtl" lang="ar"> arabic text </h3> :

  • dir="rtl"告知文本是 arabix
  • lang="ar"从右到左呈现表单

关于android - Android webView 中的阿拉伯语自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32013293/

相关文章:

java - 关闭自定义对话框

javascript - Android webview 在渲染 html 时返回不工作

ios - 如何在不使用多个 webview 的情况下更改 webview 的 url

css - 了解字体系列

css - Assets 管道无法正确加载字体

android - AES算法是适合android的加密算法吗?

android - 从 Android 上传图像到 PHP 服务器

android - 如何将 Apache HTTP API(旧版)作为编译时依赖项添加到 Android M 的 build.grade?

Android webview & localStorage

html - 这个 css 标签 : font-family "URWPSK+ArialMT"? 中的大写字母是什么意思: