【问题标题】:Persian font in android Appandroid App中的波斯字体
【发布时间】:2014-06-30 03:56:30
【问题描述】:

我用 phonegap 为 android 创建应用程序。

使用 html、css 和 javascript 设计的应用程序前端。我在项目的assets文件夹下有字体文件夹,并在css文件中使用@font-face来应用字体。(My font is persian)

当项目(html,css,js)在浏览器中运行的设计部分为真并应用字体时。

项目android编译时,这个字体不申请文字,而是申请数字。

请帮助我。 感谢您的帮助。

【问题讨论】:

标签: android css cordova


【解决方案1】:



在您的 android 应用程序的 assets 文件夹中添加您的 font.ttf
那么,例如,

代码

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);  

【讨论】:

  • 我没有任何组件 android (textview , ...)。我使用网络视图。
  • 我在 assets 文件夹中有 html 文件和 css 文件。如何使用 loadDataWithBaseURL?
  • @MostafaHassani :我已经找到了解决方案。如果您还没有找到答案,请告诉我。
【解决方案2】:

将您的字体放在PhoneGap www 文件夹下名为“fonts”的目录中。

使用 CSS 包括你的字体,像这样(我在这个例子中使用了 Roboto 字体):

@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');
}

无论你想在哪里应用 Roboto 字体,都可以在 css 中这样应用:即

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

请注意,对于大于 4 的 Android 版本,它可以使用捆绑字体。 但是对于 Android 版本

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

希望这会有所帮助..

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-11-21
    • 2022-08-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多