給APP全局設置字體主要分為兩個方面來介紹
一、給原生界面設置第三方字體
1、准備工作-下載第三方字體:傳送門
將文件放入工程assets目錄下。(一般個人習慣單獨命名一個文件夾放字體文件,也可直接放入根目錄,但記得改引用路徑)
2、代碼實現
a、自定義application,將第三方的字體,替換當前系統默認字體
b、定義style
<style name="AppTheme.NoActionBar"> <item name="windowActionBar">false</item> <item name="windowNoTitle">true</item> <item name="android:typeface">monospace</item> </style>
c、設置在manifests文件中設置application
<application android:name=".application.WeexApplication" android:allowBackup="true" android:icon="@drawable/app_icon" android:label="@string/app_name" android:roundIcon="@drawable/app_icon" android:supportsRtl="true" android:theme="@style/AppTheme.NoActionBar">
注:需要注意name是自定義application路徑,theme是自定義風格
二、給網頁設置第三方字體
1、加載本地HTML頁面使用本地字體
這種情況比較容易,只需要在本地文件上添加JS代碼即可
<style> @font-face { font-family: 'MyCustomFont'; src: url('file:///android_asset/fonts/textstyle.ttf'); } p{ font-family:"MyCustomFont"; font-size: x-large; } body { margin: 0; } </style>
<body style='font-family:MyCustomFont;'>
2、加載網絡HTML頁面使用本地字體
將網絡頁面字體轉換可以參考如下網址:http://blog.csdn.net/aiynmimi/article/details/52777965