如何在Android中正确显示阿拉伯字母?

时间:2018-09-10 10:11:32

标签: android textview arabic

我的应用程序显示阿拉伯语字母和单词。但是这些字母看起来不对。例如符号َ和شَ:

正确(来自iOS):

Correct

错误(来自Android):

Wrong

如您所见,字母顶部的小线必须居中。但事实并非如此。如何像iOS一样在Android上显示阿拉伯符号?

更新:我正在尝试使用Better-Arabic-Shapper,但它也显示不正确:

更好的阿拉伯语包装

Better-Arabic-Shapper

我正在尝试使用以下代码设置自定义字体(Arial,Simpo,nassim_latn_rg),但它也无法正常工作:

private const val FONT_PATH = "fonts/"

val font = "nassim_latn_rg.otf"
val typeface = Typeface.createFromAsset(context.assets, FONT_PATH + font)
textView.typeface = typeface

1 个答案:

答案 0 :(得分:0)

application 标签放置的 AndroidManifest.xml 文件中

android:supportsRtl="true"

允许使用阿拉伯语。如果不起作用,则需要根据要求在TextView /其他视图上设置 gravity

编辑

访问此link以重塑您的阿拉伯语。他们使用Better-Arabic-Shapper作为解决方案

编辑2

我刚刚在我的Redmi设备上进行了测试,它的显示类似于iOS。

Tested version

test_activity.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal">

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="بَ"
    android:textSize="40sp"
    android:layout_margin="20dp"/>

<TextView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="شَ"
    android:textSize="40sp"
    android:layout_margin="20dp"/>

</LinearLayout>

编辑2:即使在使用API​​ 28的PIXEL模拟器上,它也可以正常显示。检查以下图片:

Pixel emulator