不同的字体使用书法图书馆的一些活动 [英] Different font for Some activities using Calligraphy Library
问题描述
我使用书法图书馆在我的应用程序中使用自定义字体。我用设置自定义字体我的整个应用程序通过默认的字体 CalligraphyConfig
,在我的应用
类的<code> #onCreate()方法,它是工作的罚款。问题是当我需要改变一个活动(SettingsActivity)的字体。
I am using Calligraphy Library for using custom font in my application. I set a custom font to my whole application by default font using CalligraphyConfig
, in my Application
class in the #onCreate()
method and it is working fine. Problem comes when I need to change font of one activity (SettingsActivity).
我尝试使用自定义的字体在风格然而,它并没有更改字体活动。
I tried using custom font in style however It didn't change the font of activity.
以下是风格的code
Following is the code of Style
<style name="EnglishActivitiesTheme" parent="AppTheme">
<item name="android:textViewStyle">@style/AppTheme.Widget.TextView</item>
</style>
<style name="AppTheme.Widget.TextView" parent="android:Widget.Holo.Light.TextView">
<item name="fontPath">fonts/Roboto-Regular.ttf</item>
</style>
在清单
<activity
android:name=".SettingsActivity"
android:theme="@style/EnglishActivitiesTheme"
android:parentActivityName=".MainActivity" >
<meta-data
android:name="android.support.PARENT_ACTIVITY"
android:value=".MainActivity" />
</activity>
我做得不对,虽然风格的方法自定义字体?还是有更好的这样做的方法是什么?
Am I doing something wrong with custom font though style method? or Is there better method of doing this?
推荐答案
看起来它是因为应用程序兼容性在运行时创建一个不同的版本按钮/ textviews的。
Looks like it's because of AppCompat creating a different version of buttons/textviews at runtime.
在你的应用程序中的书法启动,添加一行:
In your Calligraphy startup in your Application, add the line:
.addCustomStyle(AppCompatTextView.class, android.R.attr.textViewStyle)
喜欢的东西来结束:
to end up with something like:
@Override
public void onCreate() {
super.onCreate();
CalligraphyConfig.initDefault(new CalligraphyConfig.Builder()
.setDefaultFontPath("fonts/some-other-custom-font.ttf")
.addCustomStyle(AppCompatTextView.class, android.R.attr.textViewStyle)
.setFontAttrId(R.attr.fontPath)
.build()
);
//....
}
和应该把你的textviews照顾。
And that should take care of your textviews.
编辑:
这现在应该是固定与 https://github.com/chrisjenx/Calligraphy/pull/ 191 ,目前作为一个快照。
This should now be fixed with https://github.com/chrisjenx/Calligraphy/pull/191, currently as a snapshot.
这篇关于不同的字体使用书法图书馆的一些活动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!