In this example we’ll show you how to support hindi, bangala, marathi fonts in Android application. Android phone doesn’t support Devanagari fonts. However if you want to use hindi, tamil, bangali or other Devanagari fonts in your Android Application you have an alternative of using external fonts. Follow below steps to achieve this
- Download an external Devanagari font that you like to use in your application. Here in this example, I have downloaded “Ananda-Lipi-Bold” font. You can also download from here
- Create a new folder “fonts” under assets and copy the downloaded .ttf font to your assets/font folder.
- Load .ttf to your TextView
Activity Layout
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#900001" android:padding="@dimen/activity_vertical_margin" > <TextView android:id="@+id/textView" android:gravity="center_horizontal" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_centerInParent="true" android:text="@string/hanuman_chalisa" android:textColor="#ecaa00" android:textSize="28sp" /> </RelativeLayout>
String.xml file
<?xml version="1.0" encoding="utf-8"?> <resources> <string name="app_name">HindiFont</string> <string name="hanuman_chalisa"> श्रीगुरु चरण् सरोजरज, निजमनमुकुर सुधार ।\n बरणौ रघुबर बिमल यश, जो दायक फलचार ॥\n\n बुद्धिहीन तनु जानिके, सुमिरौं पवन कुमार ।\n बल बुद्धिविद्या देहु मोहिं, हरहु कलेश विकार ॥ </string> </resources>
Activity Java Code
import android.app.Activity; import android.graphics.Typeface; import android.os.Bundle; import android.widget.TextView; public class MainActivity extends Activity { @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); TextView tv = (TextView) findViewById(R.id.textView); Typeface fontHindi = Typeface.createFromAsset(getAssets(), "fonts/Ananda Lipi Bold Cn Bt.ttf"); tv.setTypeface(fontHindi); } }