Hindi font with API level 15 (aka Android 4.0.2)

I have a hindi-based android application and I used the devangiri font from the Android API 16 SDK and renamed hindi.ttf. Text is rendered at API level 16 and 17, but is simply torn at API level API 15 and lower.

Are there any reasons why I can fix this without removing support for lower API levels. My code for setting up textview:

import android.app.Activity; import android.graphics.Paint; import android.graphics.Typeface; import android.os.Bundle; import android.view.GestureDetector; import android.widget.TextView; public class Prayer extends Activity { // TextSwitcher vs; GestureDetector gestureDetector; static Tips tip = null; static StringBuilder quesString = null; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.prayer); TextView tv1 = (TextView) findViewById(R.id.textView1); Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/hindi.ttf"); tv1.setTypeface(tf); tv1.setText("श्री"); tv1.setPaintFlags(tv1.getPaintFlags() | Paint.SUBPIXEL_TEXT_FLAG); } } 

XML format:

 <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: enter image description here

Expected: enter image description here

+4
source share
2 answers

I ran into a similar problem when I was developing a Hindi application. However, the error was resolved when changing the font files.

In addition, the IMHO device simply replaces the UTF-8 characters in the text with the corresponding characters in the font files. In this case, it shows a completely different character as a whole. So, the problem should be with the font files.

Give me your email if you want to use my font files.

+5
source

To support Hindi, I provided the DroidSansDevanagari-Regular.ttf font added in Jellybean. You can find all Jellybean Android fonts in your SDK directory under:

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

If you still see the gap in 4.0.2, you can try:

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

When setting up dynamic textSize use this:

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

All Articles