更改库项目中使用的组件的字体

时间:2016-04-15 07:00:24

标签: android android-theme android-styles android-library

是否可以更改android库项目中使用的组件的字体?

更具体一点:我正在使用图书馆' Onboarder'在第一次启动应用程序时显示介绍。现在我需要在显示文本的地方使用某种字体。使用' Caligraphy'我能够在其他地方引入新字体。

我已经在我自己的布局文件中定义了一个适用于TextViews的样式:

<style name="TextViewStyle" parent="android:Widget.TextView">
    <item name="fontPath">fonts/myCustomFont.ttf</item>
</style>

AppTheme:

<style name="AppTheme" parent="Theme.AppCompat.Light.NoActionBar">
    [...]
    <item name="android:textViewStyle">@style/TextViewStyle</item>
    [...]
</style>

库项目也使用纯TextView而没有任何样式,但不知何故我的样式不适用于它们。

有没有办法在不使用GitHub存储库的情况下更改这些TextView上的字体?

这可能是相关的:How to override styles of a library which has its own Activity

提前感谢您的帮助。

1 个答案:

答案 0 :(得分:0)

我终于找到了这个问题:

这与书法的运作方式有关。我缺少attachBaseContext中CalligraphyContextWrapper的委托。扩展 OnboardingActivity 类并覆盖 attachBaseContext()完成了这项工作:

@Override
protected void attachBaseContext(Context newBase) {
    super.attachBaseContext(CalligraphyContextWrapper.wrap(newBase));
}