Custom Font Not supporting in Android Device - android

Hi am developing One Android App in which am using Custom font .TTF file.The problem is i tested with same Branded Device with Different Build Version.the Older Version Device supporting Custom Font But new version Device not taking Custom Font.

i have one suggestion add those font in assets and make your text in html thus you can add it in Web View android
Hope it will work for your case:
WebView view = new WebView(this);
view.setVerticalScrollBarEnabled(true);
view.loadUrl("file:///android_asset/demo/intro.html");
((LinearLayout)findViewById(R.id.introLayout1)).addView(view);
view.setBackgroundColor(Color.BLACK)

first download the needed the ttf file (Font style which you want ). and put that it in the assets folder in android project. then add the following code in java file..
TextView txt = (TextView) findViewById(R.id.custom_font);
Typeface font = Typeface.createFromAsset(getAssets(), "Eltpan-n.ttf");
txt.setTypeface(font);
hope it will help you.. its worked like a charm for me .. if you satisfied vote for my answer

Related

I can't apply Typeface programmatically for Google font in Android Studio

I added a Google font using Android Studio,
It created a 'font' folder and under it is an XML file as follow:
res -> font -> font_name.xml
I'm trying to apply it programmatically but I can'y find how to do it,
I've tried several codes but nothing worked, examples:
Typeface font = Typeface.createFromFile("font/font_name.xml");
or
Typeface font = Typeface.createFromAsset(getAssets(), "#font/font_name");
Please note,
The 'font' folder along with the 'font_name.xml' file,
Were created automatically by Android Studio.
Your help would be appreciated,
Thank you.
I am certainly not an expert, but I managed to get my Typefaces working.
Firstly, this thread contains a lot of useful info:
Custom fonts and XML layouts (Android)
Now specifically to your problem, the way I managed to get Typefaces to work is by downloading a .ttf file either somewhere online, or when using android studio and clicking more fonts, set the radio button to add font to project. That will download the .ttf to res\font\font.ttf Move it to your assets directory into fonts folder and then create the typeface like this:
Typeface typeface = Typeface.createFromAsset(getAssets(), "fonts/font.ttf");
If you want to use your font often and don't want to bother setting it every time, a good idea might be extending a TextView or whatever class you need and using the .setTypeface() method in the custom constructor.
Just solved this myself, here is what I have put together.
Typeface font = Typeface.create("cursive", Typeface.NORMAL);
Log.e("Setup", "Font: " + font.getStyle());
signatureButton.setTypeface(font);
The log just checks if you have selected an acceptable font, it should return 0 if not. The hardest part was finding a font family that worked. The key is to go to your XML file and type "android:fontFamily=" from here a suggestion list should pop up with choices at the bottom.
To change the google font family
Typeface typeface = ResourcesCompat.getFont(this, R.font.your_font);
textView.setTypeface(typeface);
Add that to your fonts folder then use them in the XML or programmatically.

How use Android supplied (custom) fonts?

According to the Android Typography page Roboto font was introduced in Ice Cream Sandwich. I can download the .ttf files there or I can find it (and many others) in the <android-sdk>/platforms/android-x/data/fonts directory (where x is ICS version and higher).
If I want to actually use this font in my app do I still need to copy this to my assets/fonts directory and setup the font like this or is there some other way of accessing it in my layout XML files?
EDIT:
To clarify the question I really mean any of the Android supplied fonts. So if you look in Android Lollipop's font folder (android-sdk/platforms/android-21/data) there are lots of new fonts.
Assume on a single layout I want to use Roboto-Italic in one TextView and (say) NotoSerif-Bold in another. Can I specify that in my XML layout file using android:typeface="..." or do I need to manually copy the required .ttf files to my font folder and subclass the TextView widget?
Hi you would need to set the typeface on a TextView like below:
Typeface yourTypeface = Typeface.createFromAsset(getContext().getAssets(), "fonts/" + fontName + ".ttf");
yourTextView.setTypeface(yourTypeface);
The Roboto font is already used by default on android 4.0 and up, so you don't need to do anything.
If you want set Roboto as your font, you must verify what is your version, if you have Android < 4.0 you must do something like this
Typeface font = Typeface.createFromAsset(getAssets(), "fonts/roboto.ttf");
TextView text = (TextView) findViewById(R.id.text);
text.setTypeface(font);
But if your version is 4.0 or higher as JonasCz says, is not necessary, you can read more about this in https://developer.android.com/design/style/typography.html
Note: copy the fonts to assets/fonts. This code is useful also to put any font in your views.

Custom Fonts not working in lollipop?

I have developed a handwriting app .And one of the main feature of this is that we can change the fonts from default font to 4 other custom fonts ie, to
Vicmorg (Vic Modern Cursive)
Cursive Writing 7
Dnealiancursive
Print-Regular
And this is working fine in all devices.Yesterday I updated my nexus 10 to lollipop .Now the fonts are not taken correctly, vicmorg.ttf and Dnealiancursive.ttf are now not working but Print-Regular and Cursive Writing 7 are working .No issues in other phones though. Is there a fix for this ? Please help.
re-convert your whatever fonts to .ttf from this link works for me.
http://www.freefontconverter.com/
I did it in following way:
I have updated TextView with androidx.appcompat.widget.AppCompatTextViewand it works for each device.
Example
From
<TextView
To
<androidx.appcompat.widget.AppCompatTextView
Hope it helps you.
Error on lollipoop
test files .otf run correctly but .ttf not.
my solution for files .ttf was convert to .otf
http://www.files-conversion.com/font-converter.php
or
http://www.font2web.com/
for custom font for example, inside assets folder (../assets/fonts/birdman-webfont.otf):
Typeface birdman = Typeface.createFromAsset(getAssets(), "fonts/birdman-webfont.ttf");
TextView text= (TextView) findViewById(R.id.text);
text.setTypeface(birdman);
note: if your file is .ttf and show ERROR in the convertion, change the extension to .otf manually and convert with http://www.files-conversion.com/font-converter.php

Android Arabic/Farsi Fonts

I am developing an Android aap that uses Arabic Fonts.
I have successfully display Arabic text by using "tahoma.ttf"
But problem is that these Arabic Fonts Didn't give a cool look.
So i wanted to change that Font Style. Is there any way of doing this ?
If you want to use external font do :
First step is to pick a font that you want to use.
Create a fonts folder in your assets directory and copy your font there.
To access your custom font,use the Typeface class in the Android SDK to create a typeface that Android can use, then set any display elements that need to use your custom font appropriately.
Unfortunately, you can no longer use layout XML for this, since the XML does not know about any fonts you may have tucked away as an application asset.You can do like this in your code:
Typeface tf = Typeface.createFromAsset(getAssets(),"fonts/BPreplay.otf");
TextView tv = (TextView) findViewById(R.id.CustomFontText);
tv.setTypeface(tf);
Note: Android does not seem to like all TrueType fonts.So, if you try to use a different font and it does not seem to be working, it may be that the font is incompatible with Android, for whatever reason.
You can see more details in these pages:
Fun with Fonts
Musings of the Bare Bones Coder/using custom fonts

Use hindi in android

I want to create an android application in which the user should be able to select a language of his choice(English/ Hindi/ Marathi).
I have checked some android forums and found that android does not support Devanagari fonts.
Is there a solution? Also, is there a solution without rooting the device?
As Devanagari fonts are not supported by Android, you can still give that support to your Application.
For Hindi font copy font file (saral.ttf or Shusha.ttf or any font hindi file) to your asset folder. then use the following code.
TextView text_view = new TextView(this);
Typeface font = Typeface.createFromAsset(getAssets(), "saral.TTF");
text_view.setTypeface(font);
text_view.setText("हिंदी");
the same way u can give support for marathi....
you can use following i18n solution for different languages
http://www.vogella.de/blog/2011/01/17/translating-android-applications-i18n/
http://www.kobu.com/i18n/android/index-en.htm

Categories

Resources