How to add a font to an Android application

I am making one application in Android 2.2 in this application. I want to show Hindi text in a TextView in an Android application. (how to add the word "म ैं छात्र ह ूँ" as text)

Please help me..

+5
source share
2 answers

Add your font to the resource folder in your project and use the snippet below

 TextView hindiTextView=(TextView)findViewById(R.id.txtbx);
 Typeface hindiFont=Typeface.createFromAsset(getAssets(),"fonts/fontname.ttf");
 mytextView.setTypeface(hindiFont);

Hope this will be helpful.

+17
source

1) add the folder "fonts" inside the folder "assets" and insert the font inside the folder fonts

2) in the layout file:

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

    <TextView  
           android:id="@+id/custom_font"  
           android:layout_width="fill_parent"  
           android:layout_height="wrap_content"  
           android:text="मैं छात्र हूँ"  
           />  

3) In the operation where you want to set the text, use the following code:

 TextView txt = (TextView) findViewById(R.id.custom_font);  
 Typeface font = Typeface.createFromAsset(getAssets(), "hindifont.ttf");  
 txt.setTypeface(font);  
+3
source

All Articles