I have a question. How Can I set font for example: Harrington in textview. I use:
Typeface type = Typeface.createFromFile("C:/Fonts/Kokila.ttf");
gameResult.setTypeface(type);
gameResult = (TextView) findViewById(R.id.textViewResult);
but this solution is not working. Any ideas?
first place your font in assets folder then like:
gameResult = (TextView) findViewById(R.id.textViewResult);
Typeface type = Typeface.createFromAsset(getAssets(),"fonts/Kokila.ttf");
gameResult.setTypeface(type);
You are trying to access the font from your PC! Your phone does not have access to the 'C:/' drive of your PC, and therefore cannot load the font. You need to place the Font into the Assets folder of your application, and then read it from there.
You can read a file from the Assets folder using
context.getAssets().open(fileName);
Related
Is, any professional font family available on android. If it is not available, then how to use professional fonts in android. Thanks in advance
You can flow this step:
1.Go to the (project folder)
2.Then app>src>main
3.Create folder 'assets>fonts' into the main folder.
4.Put your 'abc.ttf' into the fonts folder.
AssetManager am = context.getApplicationContext().getAssets();
typeface = Typeface.createFromAsset(am,
String.format(Locale.US, "fonts/%s", "abc.ttf"));
setTypeface(typeface);
To add a font to your App, place the font file in asset folder and use the following code to set it to text view...
TextView textView = (TextView) findViewById(R.id.textView);
Typeface typeFace = Typeface.createFromAsset(getAssets(),
"fonts/digital.ttf");
textView.setTypeface(typeFace);
to get the fonts follow this link.
https://fonts.google.com
These are the google recommended fonts.
AssetManager mgr=getAssets();
Typeface tf=Typeface.createFromAsset(mgr, "fonts/cube.ttf");
textView.setTypeface(tf);
The method above can modify font of the TextView, but I do not want to do it like this. My idea: The user can download the font on the internet and store it in the sd-card. Then the user can apply the font they just downloaded to the widget. I feel this method can reduce the size of the project. Any suggestions?
1.) Download "font.ttf" (Replace with your ttf file name) File to external storage through the internet.
2.) Do this.
Typeface typeface = Typeface.createFromFile(
new File(Environment.getExternalStorageDirectory(), "font.ttf"));
textView.setTypeface(tf);
I want to make a application in which i needs to show the textview in gujarati language.
I tried with
Typeface tf = Typeface.createFromAsset(getAssets(), "G-SARAL1.TTF");
text.setTypeFace(tf);
but this is not working, I set the gujarati text in string.xml file and then i set that string in the textview, but when i run the application, it display square boxs instead of gujarati character,
can anyone help me , how can i implement this task.
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.
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 support for hindi file.
Try this code this 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 જજોની બેન્ચે આજે આ ચુકાદો આ");
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
fun setFonts(context: Context, fontName: String) {
val typeface = Typeface.createFromAsset(context.assets, fontName)
setTypeface(typeface)
}
To create localized string file you can also use Translations Editor.
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
TextView text_view = (TextView) findViewById(R.id.txtMsg);
//TextView text_view = new TextView(this);
Typeface faceShruti = Typeface.createFromAsset(getAssets(),
"shruti.ttf");
text_view.setTypeface(faceShruti);
text_view.setText("In Gujarati\n" + "સ્વાગત");
I had an issue where a font didnt work and it gave me a FC. So I put the font file into the sdcard, and used CreateFromFile in the typeface and the font worked!
Here is the code I used for the Assets folder:
holder.tv_SuraName =(TextView)convertView.findViewById(R.id.Start_Name);
holder.tv_SuraName.setTypeface(Typeface.createFromAsset(mContext.getAssets(), "suralist_font.ttf"));
But I changed the code to this and it worked:
holder.tv_SuraName = (TextView)convertView.findViewById(R.id.Start_Name);
Typeface Font = Typeface.createFromFile(new File(Environment.getExternalStorageDirectory()+"/asd.ttf"));
Does this mean I have a problem in the Assets folder? How can I fix this? Thanks
see this
Typeface font0 = Typeface.createFromAsset(getAssets(),"fonts/AmericanDream.ttf");
tv1.setTypeface(font0);
here fonts (folder in assets) folder containing AmericanDream.ttf file inside.
like:assets-->fonts-->AmericanDream.ttf
i hope this will help u.
AssetManager assetManager1 = getApplicationContext().getAssets();
Typeface tf1 = Typeface.createFromAsset(assetManager1, "James_Fajardo.ttf");
and used in textview like
urTextView.setTypeface(tf1, Typeface.BOLD);
hope useful for u.
How to add additional font in android environment? I need to make a font like LCD with pale background numbers like this:
http://www.androidfreeware.net/img2/gps_speedometer_android_1.png
We at bangalore android developers group had done this for one of our project AutoMeter You can have a look at the code there in detail.
The code would look something like this
Typeface myTypeface = Typeface.createFromAsset(this.getAssets(),"DS-DIGIB.TTF");
waitingTimeView = (TextView) findViewById(R.id.WaitingTime);
waitingTimeView.setTypeface(myTypeface);
DS-DIGIB.TTF is the font put in the assets folder
public void setFontTextView(Context c, TextView name) {
Typeface font = Typeface.createFromAsset(c.getAssets(),"fonts/Arial.ttf");
name.setTypeface(font);
}
Download Arial font in ttf file formate and put in asset folder. Thats enough.
You want to use the android.graphics.Typeface class, which can create new Typefaces from assets or files.