Hindi font with API level 15 (aka Android 4.0.2)

匿名 (未验证) 提交于 2019-12-03 01:38:01

问题:

I have a hindi content based android app and have used devangiri font from Android API 16 SDK and renamed as hindi.ttf. The text renders fine on API level 16 and 17 but simply tears apart in Android API level 15 and lower.

Is there any why I can fix that without removing support for lower API levels. My code for setting textview is:

Layout XML:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"     xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads"     xmlns:tools="http://schemas.android.com/tools"     android:layout_width="match_parent"     android:layout_height="match_parent"     android:background="#C5C6E1"     tools:context=".Prayer" >             <TextView                 android:id="@+id/textView1"                 android:layout_width="fill_parent"                 android:layout_height="wrap_content" >             </TextView> </RelativeLayout> 

Current:

Expected:

回答1:

I faced exactly similar issue when I was developing an Hindi app. However, the error resolved when I changed the font files.

Also, IMHO the device simply replaces UTF-8 symbols in text with corresponding symbols in font files. In this case, its showing a completely different symbol altogether. So, the problem should be with font files.

Give me your e-mail in case you want to use my font files.



回答2:

For Hindi support, I backported the DroidSansDevanagari-Regular.ttf font that was added in Jellybean. You can find all the Jellybean Android fonts in you SDK directory under:

/<Android SDK Dir>/platforms/android-16/data/fonts

If you are still seeing tearing on 4.0.2, you can try:

tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); 

When setting a dynamic textSize use this:

tv1.setTextSize(TypedValue.COMPLEX_UNIT_PX, getResources().getDimensionPixelOffset(R.dimen.questionTEXT)); 


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!