How To Set Gujarati For Textview In The Android Application?
Solution 1:
As gujarati and hindi languages are not supported by Android, you can still give that support to your Application.
For Gujarati copy the C:\WINDOWS\Fonts\Shruti.TTF
file to your asset folder. Then use the following code.
TextViewtext_view=newTextView(this);
Typefacefont= Typeface.createFromAsset(getAssets(), "Shruti.TTF");
text_view.setTypeface(font);
text_view.setText("ગુજરાતી");
Shruti.TTF
file is for Gujarati font. Similarly you can add support for hindi file.
Solution 2:
Try this code this will work
TextViewmtxt= (TextView) findViewById(R.id.action_settings);
Typefaceface1= Typeface.createFromAsset(getAssets(),
"Lohit-Gujarati.ttf");
mtxt.setTypeface(face1);
mtxt.setText("પૂર્વ વડાપ્રધાન રાજીવ ગાંધીની હત્યા કરનારા 3 આરોપીઓની ફાંસીની સજા સુપ્રિમ કોર્ટે ઉમ્રકેદમાં ફેરવી નાંખી છે.આમ રાજીવગાંધીના" +
"3 હત્યારાઓને હવે ફાંસીની સજા નહી થાય.સુપ્રીમ કોર્ટમાં 3 જજોની બેન્ચે આજે આ ચુકાદો આ");
Solution 3:
You can download the Montserrat fonts, this font is use for both language English and Gujarati. If you do not want to download the saperate fonts than can use this. You can make base text and can create method like below and use the fonts. One more thing you have to pass the
funsetFonts(context: Context, fontName: String) {
val typeface = Typeface.createFromAsset(context.assets, fontName)
setTypeface(typeface)
}
To create localized string file you can also use Translations Editor.
Solution 4:
I checked out all the given solutions but no one solved my prob so I did some more and more google and found out that, you need to create assets folder first and then paste all the fonts file which you required in your application here is a little guide for how we can add assets folder in our project
Step 1 : Navigate to the top left side of an android studio where you got menu like this and just change the option from the dropdown to Packages
Step 2 : now you will see parent as app and now just right click on the app and click new and then Folder and then Assets Folder
this is how you can add Assets Folder.
once you add Assets Folder then simply paste your ttf files into that Assets folder. and follow my code for reference
TextViewtext_view= (TextView) findViewById(R.id.txtMsg);
//TextView text_view = new TextView(this);TypefacefaceShruti= Typeface.createFromAsset(getAssets(),
"shruti.ttf");
text_view.setTypeface(faceShruti);
text_view.setText("In Gujarati\n" + "સ્વાગત");
Post a Comment for "How To Set Gujarati For Textview In The Android Application?"