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

时间:2015-08-14 15:12:30

标签: android webview fonts

我正在尝试将阿拉伯语自定义字体添加到webView而没有运气。在我的例子中,webView呈现设备附带的默认字体。

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

这是我的代码:

存储在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");
    }
 ...........
 ...........

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

1 个答案:

答案 0 :(得分:1)

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

  • dir="rtl"告知文本为阿拉伯语
  • lang="ar"从右到左呈现表单