0

My app is a malayalam news portal and in that app I'm using MLW-Panini.ttf which is a malayalam font.
The problem is that in one textview itself I'll have to display both malayalam and english text.

English content is not being displayed properly if I use the font.
If the content is only in malayalam it works fine. Considering the attached image, the content inside red line should have been in english but that is in malayalam.

Content inside green line is in malayalam and that is really fine. Requesting for a help...

TextView tv = new TextView(NewsDetail.this);
Typeface font1  = Typeface.createFromAsset(getAssets(),"fonts/MLW-Panini.ttf");
tv.setTypeface(font2);
tv.setText(Html.fromHtml(arrList.get(i).get("news")));`
thepoosh
  • 12,497
  • 15
  • 73
  • 132
Wells
  • 91
  • 7
  • i suggest using a font that supports both malayalam and english – njzk2 Jan 02 '13 at 14:07
  • how you are setting the font to a TextView, Please paste that code to help you – TNR Jan 02 '13 at 14:08
  • you should use different textview for different language so that you can easily set different fonts – maninder singh Jan 02 '13 at 14:12
  • @Nagaraj436 : I've added the code now. – Wells Jan 03 '13 at 06:12
  • @maninder singh : it is suppose to be in one textview and sometimes the server sends us malayalam content sometimes it would be mixed up with english(eg: for email addresses they can't use malayalam font), and there is no condition that we have to check which one will have malayalam alone and which one will have mixed(both malayalam and english) contents. – Wells Jan 03 '13 at 06:33

3 Answers3

0

As @njzk2 said you can try to support both of the languages,

And as for setting the font for text view take a look on this StackOverFlow Question.

Hope it helps.

Community
  • 1
  • 1
osayilgan
  • 5,873
  • 7
  • 47
  • 68
0

Use the below code:

For your First Text View:

TextView tv = new TextView(NewsDetail.this);
Typeface font1  = Typeface.createFromAsset(getAssets(),"fonts/MLW-Panini.ttf");
tv.setTypeface(font1);
tv.setText(Html.fromHtml(arrList.get(i).get("news")));

For your Second Text View:

TextView tv1 = new TextView(NewsDetail.this);
Typeface font2  = Typeface.createFromAsset(getAssets(),"fonts/secondfont.ttf");
tv.setTypeface(font2);
tv.setText(Html.fromHtml(arrList.get(i).get("news")));

Instead of creating Typeface again and again you can take define static method which returns Typeface in Utility Class. In this way you decrease the number Typeface objects and can maintain unique font all the time.

TNR
  • 5,839
  • 3
  • 33
  • 62
0

You can do it this way.

TextView tv = new TextView(NewsDetail.this);
Typeface font1  = Typeface.createFromAsset(getAssets(),"fonts/MLW-Panini.ttf");
tv.setTypeface(font1);

String text = "malayalam_text english_text";
Spannable s  = new SpannableString(text);
s.setSpan(new TypefaceSpan("sans"), "malayalam_text ".length(), "malayalam_text english_text".length(), Spannable.SPAN_EXCLUSIVE_EXCLUSIVE);
tv.setText(s);
  • it is suppose to be in one textview and sometimes the server sends us malayalam content sometimes it would be mixed up with english(eg: for email addresses they can't use malayalam font), and there is no condition that we have to check which one will have malayalam alone and which one will have mixed(both malayalam and english) contents. so your answer doesn't seem to be fine at the issue I have and I did try your answer but it is not working. – Wells Jan 03 '13 at 08:59
  • content server sends is in unicode? MLW-Panini.ttf font is unicode font or not? – Yasas Karunarathna Jan 03 '13 at 09:40