Hasnain
Hasnain

Reputation: 461

Appcelerator Android Custom Fonts not working

I am using custom fonts for android app. But it looks like its not working in classicJs app with SDK 5.2.2

I have tried making a new test project to test fonts but its also not working in test project. I am using GothamBook and GothamBold mainly. But its look like its not working for other fonts as well. for example SpicyRice-Regular

I am using Appcelerator Studio, build: 4.5.0.201602170821 with latest SDK 5.2.2.GA. you can check test app here.

Upvotes: 0

Views: 461

Answers (2)

abada henno
abada henno

Reputation: 740

Custom fonts are a quick and easy way to personalize or brand your application. Titanium Mobile supports TrueType and OpenType fonts on both iOS and Android. There are some differences between how fonts are referenced on iOS and Android that need to be considered.

Android expects fontFamily to be the font's file name without the file extension (.otf or .tff). iOS expects fontFamily to be the font's PostScript name (see Finding a font's PostScript name). This name is embedded in the font file and does not change if you rename the file.

For example, in the following code the file name of the Burnstown Dam font is "burnstown_dam.otf". For an Android application you therefore assign the value burnstown_dam to fontFamily:

"#burnstowndam": { 
  font: {
      fontFamily: 'burnstown_dam'
  }
}

The PostScript name for Burnstown Dam is BurnstownDam-Regular, so for an iOS application you assign that value to fontFamily:

"#burnstowndam": { 
  font: {
      fontFamily: 'BurnstownDam-Regular'
  }
}

http://docs.appcelerator.com/platform/latest/#!/guide/Custom_Fonts

Upvotes: 0

Hasnain
Hasnain

Reputation: 461

So apparently it was a trivial mistake. The folder name which have all the fonts files should be named 'fonts' not 'font'.

The other thing that I noticed, if you are using non alloy (classicJs) approach the folder name which contain your all app code and assets should be named 'Resources' not 'resources' .. :)

Upvotes: 3

Related Questions