BArtWell
BArtWell

Reputation: 4044

How to correctly show Arabic letters in Android?

My application shows letters and words on arabic language. But these letters looks wrong. For example symbols بَ and شَ :

Correct (from iOS):

Correct

Wrong (from Android):

Wrong

As you can see, the little line on the top of letters must be centered. But it's not. How to show Arabic symbols on Android like on iOS?

UPDATE: I am trying to use Better-Arabic-Shapper, but it's also displaying incorrectly:

Better-Arabic-Shapper

Better-Arabic-Shapper

I am trying to set custom fonts (Arial, Simpo, nassim_latn_rg) with the code below but it also doesn't work correctly:

private const val FONT_PATH = "fonts/"

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

Upvotes: 10

Views: 2638

Answers (2)

Rahul Khurana
Rahul Khurana

Reputation: 8835

In AndroidManifest.xml file under application tag put

android:supportsRtl="true"

to allow arabic language. If it doesn't works you need to set gravity on the TextView/other views according to the requirement.

EDIT

Visit this link to reshape your arabic language.They used Better-Arabic-Shapper for the solution

EDIT 2

I just tested this on My Redmi device and it is showing like 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>

EDIT 2: Even on the PIXEL emulator using API 28 it is showing fine. check the image below:

Pixel emulator

Upvotes: 0

user1506104
user1506104

Reputation: 7076

I tried with Roboto font, it works fine. All app settings are default. I did not have to add android:supportsRtl="true" in my manifest.

<style name="RobotoRegular">
    <item name="android:fontFamily">sans-serif</item>
</style>

Result:

enter image description here

Please try this font and revert if you still encounter the issue. I have a feeling this is a font-related issue.

Upvotes: 3

Related Questions