I have two unfocused TextView in the single layout. I want to show Arabic text on one TextView and English text on another TextView. I have use values/strings.xml for English and values-ar/strings.xml for Arabic text. My problem is Arabic text not showing in the TextView. If I change the custom locale to ar means its showing. How to show the Arabic text without changing the custom locale?
Put both arabic and english text in each strings.xml
Its default behaviour for Android. It will take locale information from system and map appropriate string resource from values-ar.
Text you want to show in Arabic you have to take entry in values/strings.xml and have to put those arabic character that you want to display.
please share the result when you tried this.
To do this we need the font file for Arabic fonts. For example ,we have the Arabic font file name as arabicfont.ttf. Save this file into the assets folder then use the bellow code
arabicTextview.setTypeface(Typeface.createFromAsset(getContext().getAssets(),"arabicfont.ttf"));
arabicTextView.setText("ur text");
Like wise we can set any type of text with out using the Locale
Related
I read on Stack Overflow how to create a custom bold font and a regular one:
How to create custom font family with bold font
But I'm struggling to understand how to implement this in my strings. Ordinarily you simply use <b></b> to make text bold, but this doesn't seem to work with my custom fonts. All the text remains the same.
I know that you have tried adding the bolded font to a font family, but it hasn't worked. You can try one of the ways below. It will work even if you do import a TTF font.
One way you can do it is in strings.xml
You can create a new string and then add the b to bold it like this:
<string name="my_string"><b> My String</b></string>
You will need to create one for each string that you want to bold.
Then in your layout file, you can set the android:text to one of the strings from strings.xml and you can set the android:fontFamilyto the TTF font.
You can also bold it programmatically using the SpannableString in Java. Check this article to see how to bold programmatically.
Hope it helps!
i am currently working on one Android Application and i have to set layout according to country like if application is for Korea layout color must be blue and for india layout color must be red.
So how can i achieve that?
i know about multiple language
values-kr // for Korea
values //for English
values-fr // for french
but for layout i don't know.
Help Me.
Thanks in Advance
You can create a Style for each Values or in java code programming you can use a simple if statement that detects your location inside "oncreate method" and setbackground layout according to what you want using a drawable.
You have to determine your system language. You can use
Locale.getDefault().getLanguage();
to get the usual language code (e.g. "de", "en").
Then, create a base Activity for your app and override onCreate to set the theme according to your system language. Derive all your other activities from this base Activity. Check this tutorial.
follow type of languages
res/values/strings.xml
Contains English text for all the strings that the application uses,
including text for a string named title.
res/values-fr/strings.xml
Contain French text for all the strings, including title.
res/values-ja/strings.xml
Contain Japanese text for all the strings except title.
How to display Korean Words in android app
You may use this piece of code:
TelephonyManager tm = (TelephonyManager)context.getSystemService(Context.TELEPHONY_SERVICE);
String locale = tm.getSimCountryIso();
and choose:
if (locale.equals(pk))
{
view = inflater.inflate(R.layout.hazel_quick_form, container, false);
} //fragment
Take example of TextView.
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/hello_world"
android:textColor="#color/textcolor" />
you can have colors.xml file in different locale folders like values , values-fr etc.
In example textview #color/textcolor can be defined with those saperated colors.xml files with different colors for different locales.
look at this.
Android will do the next magic automatically based on locale.
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/>
I have an app that read load up a text file and display the text. Now, the text file could be in English, Chinese, or whatever language. My question is, how do I properly display the characters without showing gibberish. Thanks!
refer to this link.
How to display korean text on Textview?
You require a True Type font(ttf) file to support the language you wish. Include the respective font file into your assets folder and try this code.
TextView text = (TextView) findViewById(R.id.textView1);
Typeface font=Typeface.createFromAsset(activity.getAssets(), "your-choice-font.ttf");
holder.text.setTypeface(font);
holder.text.setText(content_read_from_TxtFile);
I am trying to display local Indian languages in my application. The data for the application is from web. I use a web service to display the contents from DB. I am converting the data in format of unicode and i receive the unicode in phone. Am trying to display the unicode and also i use the relevant font If telugu i use telugu fonts.
The unicode is displayed but there is spacing problem. To solve this i got a option of reshaping, that is like giving space with fixed codes and got for Arabic but i am now searching for telugu.
My reffered link is:
Refference for Arabic
You can put in HTML codes for the devanagari characters. There are quite a lot of online editors that will give these codes, like:
-> http://www.wandel.person.dk/hindi.html
(A text editor which you can use to write devanagari characters)
-> http://vikku.info/indian-language-unicode-converter/hindi-unicode-converter.html
(An english to hindi text converter)
Use Typeface option. Please see an example below
TextView text = (TextView) findViewById(R.id.text);
Typeface font = Typeface.createFromAsset(getAssets(), "myfont.ttf");
text.setTypeFace(font);