How to install gujarati for textview in android application?

I want to create an application in which I need to show text in gujarati.

I tried using

Typeface tf = Typeface.createFromAsset(getAssets(), "G-SARAL1.TTF"); text.setTypeFace(tf); 

but it doesnโ€™t work, I set the gujarati text in the string.xml file and then set this string in the text view, but when I run the application, it displays square fields instead of the gujarati character,

can someone help me how can i implement this task.

+3
source share
3 answers

Since the gujarati and hindi languages โ€‹โ€‹are not supported by Android, you can still provide this support for your application.

For Gujarati, copy the file C:\WINDOWS\Fonts\Shruti.TTF to your resource folder. Then use the following code.

  TextView text_view = new TextView(this); Typeface font = Typeface.createFromAsset(getAssets(), "Shruti.TTF"); text_view.setTypeface(font); text_view.setText("เช—เซเชœเชฐเชพเชคเซ€"); 

Shruti.TTF File is for Gujarati font. Similarly, you can add hindi file support.

+7
source

Try this code, it will work

 TextView mtxt = (TextView) findViewById(R.id.action_settings); Typeface face1 = Typeface.createFromAsset(getAssets(), "Lohit-Gujarati.ttf"); mtxt.setTypeface(face1); mtxt.setText("เชชเซ‚เชฐเซเชต เชตเชกเชพเชชเซเชฐเชงเชพเชจ เชฐเชพเชœเซ€เชต เช—เชพเช‚เชงเซ€เชจเซ€ เชนเชคเซเชฏเชพ เช•เชฐเชจเชพเชฐเชพ 3 เช†เชฐเซ‹เชชเซ€เช“เชจเซ€ เชซเชพเช‚เชธเซ€เชจเซ€ เชธเชœเชพ เชธเซเชชเซเชฐเชฟเชฎ เช•เซ‹เชฐเซเชŸเซ‡ เช‰เชฎเซเชฐเช•เซ‡เชฆเชฎเชพเช‚ เชซเซ‡เชฐเชตเซ€ เชจเชพเช‚เช–เซ€ เช›เซ‡.เช†เชฎ เชฐเชพเชœเซ€เชตเช—เชพเช‚เชงเซ€เชจเชพ" + "3 เชนเชคเซเชฏเชพเชฐเชพเช“เชจเซ‡ เชนเชตเซ‡ เชซเชพเช‚เชธเซ€เชจเซ€ เชธเชœเชพ เชจเชนเซ€ เชฅเชพเชฏ.เชธเซเชชเซเชฐเซ€เชฎ เช•เซ‹เชฐเซเชŸเชฎเชพเช‚ 3 เชœเชœเซ‹เชจเซ€ เชฌเซ‡เชจเซเชšเซ‡ เช†เชœเซ‡ เช† เชšเซเช•เชพเชฆเซ‹ เช†"); 
0
source

You can download Montserrat fonts, this font is used for English and Gujarati . If you do not want to download sacred fonts, then you can use this. You can make the base text and you can create a method as shown below and use fonts. One more thing you have to convey

  fun setFonts(context: Context, fontName: String) { val typeface = Typeface.createFromAsset(context.assets, fontName) setTypeface(typeface) } 

To create a localized string file, you can also use the Translation Editor .

0
source

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


All Articles