2

I create application for android with phonegap.

Front-end of app designed with html, css and javascript. I have font folder under assets folder in project and use @font-face in css file for applying font.(My font is persian)

When the section of design of project (html,css,js) run in browser is true and fonts apply.

When project android compile this fonts don't apply for text but apply for numbers.

Please help me. Thanks for your help.

2 Answers2

0



Add your font.ttf in assets folder of your android application.
Then, For Example,

CODE

wv = (WebView) findViewById(R.id.webView1);
String st = "<html><head><style type=\"text/css\">@font-face {font-family:MyFont;src: url(\"file:///android_asset/font/font.ttf\")}body {font-family:MyFont;font-size: medium;text-align: justify;}</style></head><body>";
String ed = "</body></html>";
String myHtmlString = st + YourText + ed;
wv.loadDataWithBaseURL(null,myHtmlString, "text/html", "UTF-8", null);  
Ullas
  • 11,450
  • 4
  • 33
  • 50
0

Put your fonts in directory called "fonts" under your PhoneGap www folder.

Using CSS include your fonts like this (I have used Roboto Fonts here in this example):

@font-face {
    font-family: 'Roboto Condensed';
    font-style: normal;
    font-weight: 400;
    src: local('Roboto Condensed Regular'), local('RobotoCondensed-Regular'), url(../fonts/RobotoCondensed-Regular.ttf) format('truetype');
}

Wherever you want to apply Roboto fonts, apply like this in css: i.e.

font: 400 1.25em/45px 'Roboto Condensed', sans-serif;

Note that, For Android Version greater than 4 it can Use bundled Fonts. However for Android Version < 4 need to download fonts From Web like this:

<link href='http://fonts.googleapis.com/css?family=Open+Sans:400,300,300italic,400italic,600,600italic,700,700italic' rel='stylesheet' type='text/css'>

Hope this helps..