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.
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.
I have built an application which displays the news in Nepali (Devnagari) font.
Everything is fine but the problem is that the font is not displayed properly in some Android phones.
Here I have posted two images showing the variation of the same content in different phones. The first one is perfect but the second one is incorrectly displayed.
1st Image with correct fonts
2nd Image with incorrect fonts
The problem I realized is that the second phone does not contained the correct font installed in it.
How can we get rid of this problem?
I have got no proper idea regarding this, but a solution that came in my mind is that - What if we integrate the necessary font along with the apk file and the font too gets downloaded with the apk.
Please pass me suggestion for this and would be grateful to know how to implement any solution that exists.
If you are using the native Android Textview Component you could use the method:
public void setTypeface (Typeface tf)
And create the typeface this way :
static Typeface createFromAsset(AssetManager mgr, String path)
Create a new typeface from the specified font data.
Typeface.createFromAsset(getAssetManager(),"RELATIVE_PATH_TO_YOUR_TYPFACE_IN_THE_ASSET_FOLDER");
If you are using Android Studio the asset folder should be created under src/main/assets.
Make 1 folder in assets named "fonts", put your font files inside that folder. e.g. see following image
import android.graphics.Typeface;
Then declare Typeface object
Typeface allFontType, allFontTypeNormal, allFontTypeLight;
try
{
allFontType = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dosis-Bold.ttf");
allFontTypeNormal = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dosis-Medium.ttf");
allFontTypeLight = Typeface.createFromAsset(getApplicationContext().getAssets(), "fonts/Dosis-ExtraLight.ttf");
}
catch (Exception e1)
{
e1.printStackTrace();
allFontType = Typeface.create(Typeface.SANS_SERIF, Typeface.BOLD);
allFontTypeNormal = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
allFontTypeLight = Typeface.create(Typeface.SANS_SERIF, Typeface.NORMAL);
}
To apply font in TextView use following code
TextView lblDaysName = (TextView)view.findViewById(R.id.lblDaysName);
lblDaysName.setTypeface(allFontTypeNormal);
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" + "સ્વાગત");
this is my tamil UTF-8 unicode string
"\u00e0\u00ae\u009c\u00e0\u00af\u0086\u00e0\u00ae\u00a9\u00e0\u00ae\u00bf\u00e0\u00ae\u00b2\u00e0\u00ae\u00bf\u00e0\u00ae\u00af\u00e0\u00ae\u00be \u00e0\u00ae\u00aa\u00e0\u00af\u0081\u00e0\u00ae\u0095\u00e0\u00af\u0088\u00e0\u00ae\u00aa\u00e0\u00af\u008d\u00e0\u00ae\u00aa\u00e0\u00ae\u009f\u00e0\u00ae\u00ae\u00e0\u00af\u008d"
i want to decode it and display the tamil font
in android is this posible,how to do ?
please help me
You can save the tamil (ttf) font in the assets folder, and use it like this:
TextView text; // initialize to your textview
Typeface tf = Typeface.createFromAsset(this.getAssets(),"fonts/tamil.ttf");
text.setTypeface(tf);
Step 1: Download a tamil font .ttf file. (For example say kanchi.ttf).
Step 2: Now create a directory "fonts" in your assets folder in the android project.
Step 3: Now copy the kanchi.ttf file into assets/fonts folder in you Android project.
Step 4: Add these lines to your onCreate()
protected static Typeface tamil = null;
tamil= Typeface.createFromAsset(getAssets(),"fonts/kanchi.ttf");
Step 5: Now provide this typeface to your TextView you want.
textview= (TextView) findViewById(R.id.tipstext);
textview.setTypeface(tamil);
textview.setTextSize(20);
textview.setText( "nkZk;");
The best way to display tamil in android is to use TSCII font as described here. Unicode is not yet fully supported.
if you are using webview, place the your font file 'tamilfont.ttf' in the assets folder.
and the java code will be similar to this. notice the font is applied in the css
data = "<html><head><style>#font-face {font-family: 'tamilfont';src: url('file:///android_asset/tamilfont.ttf');} h1 { font-family: 'tamilfont'; } </style></head><body> <h1>தமிழன்!</h1> </body></html>";
WebView wv = (WebView)findViewById(R.id.webview);
wv.loadDataWithBaseURL(null, data, "text/html", "UTF-8", null);
this approach does not work in android 2.0 and 2.1.
I Have one to open Tamil font convert doc to pdf and then try to open in android phones
I wanna create an application in android to install a Hindi Font. Can some one guide me how i can go about it ? is it possible ?
Add the font file you want to use in the assets folder of your Android application. Then you can load the font and use it like this:
AssetManager assetManager = getContext().getAssets();
Typeface tf = Typeface.createFromAsset(assetManager,"GILB.TTF");
TextView logo = (TextView)findViewById(R.id.logo);
logo.setTypeface(tf);
In this case, I've used the true type font Gill Sans Bold.
You cannot install a font on a device.
You can package a font as an asset with your application to be used by your application.