Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to display Sinhala Unicode characters in android app

I,m trying to show Sinhala Unicode characters in android app. when i am using Samsung tabs or phones Unicode is running it on without problem.but it does not work on other phones or tab.cause there is no Sinhala Unicode.How to do this for an example i run this code on Samsung tab successfully.

Toast.makeText(this, "අන්තර්ජාල සම්බන්දතාවය තිබේ ", Toast.LENGTH_SHORT).show();

but other phones or tab does n't work.

like image 691
Lahiru Prasanna Avatar asked Aug 19 '14 06:08

Lahiru Prasanna


2 Answers

You might need to have a Sinhalese font file (say, Sinhalese.ttf) in the directory assets/fonts in the root of your project. You create a dummy text view because it has a method called setTypeface, which sets the font for next code:

import android.graphics.Typeface;

public class FontSampler extends Activity {
  @Override
  public void onCreate(Bundle icicle) {
    super.onCreate(icicle);
    setContentView(R.layout.main);

    TextView tv=(TextView)findViewById(R.id.custom);  // a dummy text view
    Typeface face=Typeface.createFromAsset(getAssets(),
                                      "fonts/Sinhalese.ttf");
    tv.setTypeface(face);

    Toast.setView(tv).makeText(this, "අන්තර්ජාල සම්බන්දතාවය තිබේ ", Toast.LENGTH_SHORT).show();
  }
}

This way, even if an android phone doesn't have a font installed, then the font embedded in your app will serve. Hope this helps.

like image 76
RAM Avatar answered Oct 04 '22 17:10

RAM


If you want to render the Both sinhala and English in same text box then use Iskolapota font file.And do the same as @Nonymous answer says. It works for me.enter image description here

like image 21
Nithila Avatar answered Oct 04 '22 17:10

Nithila