Tutorials Android How to Use Hindi Font in Android Application

How to Use Hindi Font in Android Application

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

  1. 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
  2. Create a new folder “fonts” under assets and copy the downloaded .ttf font to your assets/font folder.
  3. 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);
	}
}

Output

Screenshot_2014-05-23-17-13-49

Total
0
Shares
guest
11 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
Akash Panchal
Akash Panchal
8 years ago

Never knew this, now i can Hindify my project.

Akshay Kant
Akshay Kant
8 years ago

getting error “r cannot be resolved to a variable”

Padam
Padam
7 years ago

Thanks 🙂

RAKESH TIWARI
RAKESH TIWARI
7 years ago

Thanks Nilanchala it is very useful for me i use it and complete our app requirement. I am also android developer and regular android blogger.

http://goo.gl/0m6Cv7

JavaTechig
JavaTechig
7 years ago

Did you check your ttf is fine ? From my experience, I have noticed devanagari font doesn’t load properly in some devices.

Nilanchala Panigrahy
Nilanchala Panigrahy
7 years ago

Looks like some code with semicolon. Can you paste the entire code?

vandi
vandi
7 years ago

I copy pasted exactly the same code you’ve presented.The error I am talking about is for the mentioned code.thanks

vandi
vandi
7 years ago

I’m pasting the entire code from the beginning:package com.example.spk.muni_darshan;

import android.app.Activity;

import android.graphics.Typeface;

import android.support.v7.app.ActionBarActivity;

import android.os.Bundle;

import android.view.Menu;

import android.view.MenuItem;

import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

@Override

protected void onCreate(Bundle savedInstanceState) {

super.onCreate(savedInstanceState);

setContentView(R.layout.activity_main);

}

@Override

public boolean onCreateOptionsMenu(Menu menu) {

// Inflate the menu; this adds items to the action bar if it is present.

getMenuInflater().inflate(R.menu.menu_main, menu);

return true;

}

@Override

public boolean onOptionsItemSelected(MenuItem item) {

// Handle action bar item clicks here. The action bar will

// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.

int id = item.getItemId();

//noinspection SimplifiableIfStatement

if (id == R.id.action_settings) {

return true;

}

return super.onOptionsItemSelected(item);

import android.app.Activity;

import android.graphics.Typeface;

import android.os.Bundle;

import android.widget.TextView;

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/DevLys 180.ttf”);

tv.setTypeface(fontHindi);

}

}

thanks

Nilanchala Panigrahy
Nilanchala Panigrahy
7 years ago
Reply to  vandi

You are wrongly adding import statement again. I have refactored your code and it compiles fine. Take the code below

com.example.spk.muni_darshan;
import android.app.Activity;
import android.graphics.Typeface;
import android.support.v7.app.ActionBarActivity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.widget.TextView;

public class MainActivity extends ActionBarActivity {

@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/DevLys 180.ttf”);
tv.setTypeface(fontHindi);
}

@Override
public boolean o nCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.menu_main, menu);
return true;
}

@Override
public boolean onOptionsItemSelected(MenuItem item) {
// Handle action bar item clicks here. The action bar will
// automatically handle clicks on the Home/Up button, so long

// as you specify a parent activity in AndroidManifest.xml.
int id = item.getItemId();
//noinspection SimplifiableIfStatement
if (id == R.id.action_settings) {
return true;
}
return super.onOptionsItemSelected(item);
}
}

Dinesh
Dinesh
7 years ago

hey i want to make simple android calculator which support devanagri number instead english(1,2,3,4,5,6).. i am making the layout but how to achive in java code of arthematic operation?

Kuldeep Chaudhary
Kuldeep Chaudhary
6 years ago

hi, Nilanchala,
i need to change hindi font at the time of sending to server. when i m send through my application text is appear like ???????? ?? ???.. i am sending through edit text so please help me out how can i change font that will support to database.

Previous Post
Data Structure Tutorials

Selection Sort Example In Data Structure

Next Post
TennisTV Android Application

TennisTV – Best Live Streaming App for Tennis fans

Related Posts
By clicking “Allow All”, you agree to the storing of cookies on your device to enhance site navigation, analyze site usage, and assist in our marketing efforts. Cookie Notice
Allow All
11
0
Would love your thoughts, please comment.x
()
x