Android multitext text

I created customFontTextView in Android, but is it possible that my customFontTextView supports the entire regional language. All font files will be listed in the assets folder

I can change the font in my customFontTextView for another font in XML, i.e. if I set Arial.ttf , than it displays the Arial font, when I change the font in XML to some hindiphon than on the Hindi show, I need to change every time in XML, so any trick to change the font runtime textview as changing the language

eg

 CustomTextView tvTitle = (CustomTextView).findViewById(R.id.tvTitle); tvTitle.setText("English Font"); tvTitle.setText("ગુજરાતી ફોન્ટ"); tvTitle.setText("हिन्दी फॉन्ट"); tvTitle.setText("same as other language font"); 

Note: on some devices, regional fonts are not supported like MOTO G, E, X, so I need this

+5
source share
1 answer

If I misunderstood your question, you want to install a font (for example: Helvetica for English, Arial for Hindi, etc.) on your text file.

Well, you can do it if you get the device locale at startup, if you get the Arial font in Hindi and set it to a text representation, otherwise you will get Helvetica.

 Typeface face = Typeface.createFromAsset(getAssets(), "fonts/Helvetica.ttf"); tv.setTypeface(face); 

You can do an “if” using Locale.getDefaultLocale and Locale.forLanguageTag (languageTag)

Note. I simplified the example with Arial and Helvetica, but I know that you are talking about multilingual fonts, just change the fonts.

It helps?

0
source

Source: https://habr.com/ru/post/1208883/


All Articles