是否可以在Android應用程序中設置自定義字體?爲什麼我的自定義字體未應用於所有應用程序?
我試了一下張貼here,但我不知道我的extends Application
類...
任何幫助嗎?
編輯:
我試過如下:
- 添加資產文件夾,然後插入字體內側,在這裏看到:
添加從
Application
延伸的新班級從我的
AndroidManifest.xml
調用此新班級。我去了我的風格,並添加它。
MyApp.java:
public class MyApp extends Application {
@Override
public void onCreate() {
super.onCreate();
FontsOverride.setDefaultFont(this, "DEFAULT", "raleway_regular.ttf");
// This FontsOverride comes from the example I posted above
}
}
的AndroidManifest.xml:
<application
android:allowBackup="true"
android:icon="@mipmap/ic_launcher"
android:label="@string/app_name"
android:supportsRtl="true"
android:name=".MyApp"
android:theme="@style/AppTheme">
....
styles.xml:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">
<item name="android:fontFamily">default</item>
</style>
但我的字體仍然沒有改變......任何想法?
然後調用MyApp
類。但對我的字體沒有影響...
編輯2:我意識到我的按鈕在爲我的按鈕設置自定義樣式後應用自定義字體。這裏是我的自定義按鈕樣式:
<style name="MyButtonStyle" parent="Widget.AppCompat.Button">
<item name="textAllCaps">false</item>
<item name="android:textAllCaps">false</item>
</style>
這裏是現在的樣子:
所以:我的按鈕應用樣式,而不是TextView
。任何想法爲什麼我的自定義字體不適用於應用程序中的所有項目?
我知道有一種方法可以一個接一個......並且這種方法可以一個一個正常工作。但我想通常... – Sonhja