可以在 Android 应用程序中设置自定义字体吗?
我试了什么是张贴 给你,但我不知道我的 extends Application
类是..。
有人帮忙吗?
编辑:
我尝试了以下方法:
添加一个从 Application
扩展的新类
从我的 AndroidManifest.xml
调用这个新的类。
我按照自己的风格加了进去。
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
}
}
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">
....
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
。知道为什么我的自定义字体没有应用于应用程序中的所有项目吗?