Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using otf type fonts in Android studio

I see a lot of references for ttf fonts in Android studio but none describe usage of otf type fonts. Is there a way to use otf type fonts as well for Android studio projects?

like image 209
Ganga Avatar asked May 18 '16 14:05

Ganga


People also ask

How do I use OTF fonts on Android?

To change font styles in GO Launcher, copy the TTF or OTF font files on your phone. Long press on the home screen and select GO Settings. Choose Font–>Select Font. Pick the font you want or tap Scan to add files stored on your device.

Is it better to install OTF or TTF?

OTF is more likely to be a “better” font, as it supports more advanced typesetting features (smallcaps, alternates, ligatures and so on actually inside the font rather than in fiddly separate expert set fonts).

How do I use OTF fonts on Android?

How do I use OTF fonts on Android? Copy your TTF or OTF font files to your phone. Long press anywhere on the home screen and select “GO Settings.” Choose Font > Select Font. Pick your font, or tap “Scan” to add files stored on your device.

How do I add fonts to my Android app?

In Android Studio Right click on app & create a folder assets. Right click on assets and create a folder fonts. Download .ttf file i.e fontName.ttf and paste inside fonts folder.

How to change font style in Android Studio?

What are the different ways to Change font Style in Android Studio. 1 In Android Studio Right click on app & create a folder assets. 2 Right click on assets and create a folder fonts. 3 Download .ttf file i.e fontName.ttf and paste inside fonts folder.

What fonts are supported by Android Studio?

Android docs doesn't specify the fonts that it supports.When Android dislikes a custom font, rather than raising an Exception, it seems to substitute Droid Sans ("sans"). TTF is always been supported. OTF was later added at least in 1.6 and later, but partially.


2 Answers

TTF is always been supported. OTF was later added at least in 1.6 and later, but partially.

Typeface face;

face = Typeface.createFromAsset(getAssets(), "font.otf");

textview.setTypeface(face);

Helpful link : Use external fonts in android

You can convert this page : http://www.ehow.com/how_6192479_convert-dfont-ttf.html , https://onlinefontconverter.com/

like image 171
Ahmad Aghazadeh Avatar answered Sep 29 '22 13:09

Ahmad Aghazadeh


You can add external fonts by adding it to the assets folder.

The Typeface class specifies the typeface and intrinsic style of a font. This is used in the paint, along with optionally Paint settings like textSize, textSkewX, textScaleX to specify how text appears when drawn (and measured).

So create an object with reference to the font places in assets folder and apply the font style by setTypeface() method.

Example:

TextView usernamesigin = (TextView)findViewById(R.id.username_signin_edittxt);
Typeface tf = Typeface.createFromAsset(getAssets(), "fonts/MyriadPro-Regular.otf");
usernamesigin.setTypeface(tf);
like image 43
Nikhil Biju Avatar answered Sep 30 '22 13:09

Nikhil Biju