我正在尝试向 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/