【问题标题】:Change fontface of components used inside a library project更改库项目中使用的组件的字体
【发布时间】:2016-08-07 00:29:30
【问题描述】:

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

更具体地说:我在第一次启动应用程序时使用库“Onboarder”来显示介绍。现在我需要在任何显示文本的地方使用某种字体。通过 'Caligraphy' 库,我能够在其他任何地方引入新字体。

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

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

应用主题:

<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

提前感谢您的帮助。

【问题讨论】:

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


    【解决方案1】:

    我终于自己找到了问题:

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-20
      • 1970-01-01
      • 2023-03-12
      • 1970-01-01
      • 1970-01-01
      • 2023-03-05
      相关资源
      最近更新 更多