Sunday, 16 June 2013

Kannada Localization in Android ( Display Kannada Font )

Demo:
Devices =>
2.3 And 4.2

1)MainActivity.java:

package com.venky.displaykannadafont;

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 tvKannada = (TextView) findViewById(R.id.tvKannada);
            TextView tvEnglish = (TextView) findViewById(R.id.tvEnglish);

            tvEnglish.setText("In English\n" + "Welcome");

            Typeface faceAkshar = Typeface.createFromAsset(getAssets(),
                        "akshar.ttf");

            tvKannada.setTypeface(faceAkshar);

            tvKannada.setText("In Kannada\n" +"ಸ್ವಾಗತ");
      }
}



2)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:background="#5F04B4"
    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:id="@+id/tvEnglish"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="51dp"
        android:text="text1"
        android:textColor="#ffffff"
        android:textSize="20dp" />

    <TextView
        android:id="@+id/tvKannada"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignLeft="@+id/tvEnglish"
        android:layout_below="@+id/tvEnglish"
        android:layout_marginTop="66dp"
        android:text="text2"
        android:textColor="#ffffff"
        android:textSize="20dp"
        android:textStyle="bold" />

</RelativeLayout>

3)TTF File:

Download akshar.ttf file and put into asset folder.
To download akshar.ttf file Click Here

4)Download this code Click Here

4 comments:

  1. Hello! If you’re interested to localize web software, PC software, mobile software or any other type of software, I warmly recommend this online collaborative localization tool: https://poeditor.com/
    It's the most effective and neat translation platform I've seen so far!

    ReplyDelete
  2. kannada fonts are in corrupted text plz do help

    ReplyDelete
  3. Hope everything is fixed now. It won't be a problem anymore.

    ReplyDelete