How to display Sinhala unicode characters in android app
I am trying to show Sinhala Unicode characters in an Android application. when i use samsung tabs or unicode phones it launches it without issue. but it doesn't work on other phones or tab.cause there is no Sinhala Unicode. How to do it, for example, I have successfully run this code in the Samsung tab.
Toast.makeText(this, "අන්තර්ජාල සම්බන්දතාවය තිබේ ", Toast.LENGTH_SHORT).show();
but other phones or tab doesn't work.
source to share
You may need a Sinhalese font file (say Sinhalese.ttf) in a directory assets/fonts
at the root of your project. You are creating a dummy text view because it has a method called setTypeface
that sets the font for the following 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();
}
}
Thus, even if there is no font installed on the Android phone, then the font embedded in your application will be used. Hope this helps.
source to share