• TekArt

    TekArt is an Organisation where people develop Android App through innovative ideas. App for the next Generation....

Tuesday 8 April 2014

Posted by Unknown
No comments | 05:17
Hello Guys , how are you today? Hope you will be fine.

Have you ever wondered how to write in Hindi or any other language in Android. In this tutorial we are going to see how to develop multilingual android application.



1) First of all, create an Android Application Project.

2) Next go to "res/layout/activity_main.xml" and create a TextView there. The code looks like

activity_main.xml

<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:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id = "@+id/text" />

</RelativeLayout>


3) Now you need to download the font file of the language you wish to use. For our case its hindi, so i downloaded the "Mangal.ttf" file. You can google for your respective font file.

4) After downloading the font file save it in "assets/font/font_file.ttf" .

5) Next go to "src/your_package_name/MainActivity.java" and paste the below code.

import android.app.Activity;
import android.graphics.Typeface;
import android.os.Bundle;
import android.widget.TextView;

public class MainActivity extends Activity {
    TextView text;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
       
        text = (TextView) findViewById(R.id.text);
        Typeface tf = Typeface.createFromAsset(getAssets(), "font/Mangal.ttf");              
        //TextView tv = (TextView) findViewById(R.id.yourtextview);
        text.setTypeface(tf);
        text.setText("यह एक अच्छा एप्लीकेशन है | इ  लव इट |");
    }

}


Note - You can download and use google input tools for converting english to your respective languages. In our case it was Hindi so i used hindi.

Now we are done. Post your questions in the comment. I will be happy to answer those.

For more info visit on facebook https://www.facebook.com/androidcoolstuffs

Thank you

0 comments:

Post a Comment