Can I put multi language in a textView ? for example could i have a textView with arabic text and english numbers?
Can I put multi language in a textView ? for example could i have a textView with arabic text and english numbers?
Solution suggested by Murillo Henrique will work as long as both texts are encoded in Unicode format.
On the other hand, when any one of the text is in non-Unicode, then we won't be able to display it in a single TextView control.
As shown above, the first TextView displays both English and Arabic texts. This is because both are Unicode texts. For this to work, one can simply combine strings in different languages as shown below.
txtUnicode.setText( "The Saved Group " + "الفرقة الناجية");
In second TextView control, the loaded text is a non-Unicode Malayalam text. To correctly display the non-Unicode text, it requires loading corresponding font as shown below.
Typeface tfMalayalam = Typeface.createFromAsset(getAssets(), "fonts/FML-TT-Leela_Heavy.ttf");
textNonUnicode.setTypeface(tfMalayalam);
textNonUnicode.setText("hnPbn¨I£n");
As it can be seen, text passed to setText
method is not readable because it is in a non-Unicode encoded form. But when correct font is supplied during runtime, it correctly displays the text.
This non-Unicode font loading will be very useful when we deal with non-Unicode texts from legacy sources.
In the third TextView control, a Unicode text is being appended to a non-Unicode text as shown below.
TextView textUnicodePlusNonUnicode = (TextView) findViewById(R.id.txtUnicdePlusNonUnicode);
textUnicodePlusNonUnicode.setTypeface(tfMalayalam);
textUnicodePlusNonUnicode.setText("hnPbn¨I£n" + " Unicode English");
Because there set a non-Unicode font, system will try to display the Unicode text using a non-Unicode encoding scheme specified by the loaded font. Hence the supplied Unicode text Unicode English
won't be displayed as expected.
As an additional info, Google is in the process of defining a universal font called Noto for Android platform. Please see this for more details.
You have 2 options:
One: type your text, but switch between varius languages in your keyboard during the typing.
Or this second one, which I recommend, because you'll have all your texts inside one file, making more easily to modify it later.
myTextView.setText(R.string.text1 + " " + R.string.text2);
In your String.xml:
<string name="text1">Your english text goes here/>
<string name="text2">Your arabic text goes here/>