Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to add font in Android Application

i am making one application in Android 2.2 in that application i want to show hindi text in TextView in Android application. (how to add "मैं छात्र हूँ" word in Text view)

Please help me..

like image 452
Prashant Kadam Avatar asked Jun 24 '11 04:06

Prashant Kadam


People also ask

How do you change the font on Android apps?

Open Settings. Tap Display. Tap Font and screen zoom. Select your choice of Font Style and you're done.

How do I manually install a font?

Right-click the fonts you want, and click Install. If you're prompted to allow the program to make changes to your computer, and if you trust the source of the font, click Yes. Your new fonts will appear in the fonts list in Word.


2 Answers

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

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

Hope its helpful.

like image 140
Jana Avatar answered Oct 06 '22 13:10

Jana


1) add "fonts" folder inside of "assets" folder and paste font inside of fonts folder

2) in 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 Activity where you want to set the text use the code below:

 TextView txt = (TextView) findViewById(R.id.custom_font);  
 Typeface font = Typeface.createFromAsset(getAssets(), "hindifont.ttf");  
 txt.setTypeface(font);  
like image 31
Prashant Kadam Avatar answered Oct 06 '22 12:10

Prashant Kadam