更改Android应用程序的所有字体
问题描述:
如何更改我的android应用程序的整个字体?
之前,我在github上看到了这篇文章。该解决方案仅对设备有效低于api21。
对于android 5,即使我们添加具有样式的
。 values-v21
文件夹,该方法也无法使用。 xml
How can I change the entire typeface of my android application?
previously I saw this post on github.The solution work fine only for devices with lower than api 21.
For android 5 this method doesn't work even if we add a values-v21
folder with styles.xml
separately.
这是我的 values-v21 / styles.xml
:
<resources>
<style name="AppBaseTheme" parent="Theme.AppCompat.Light.DarkActionBar">
</style>
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:typeface">serif</item>
</style>
</resources>
答
<style name="AppTheme" parent="AppBaseTheme">
<item name="android:textViewStyle">@style/RobotoTextViewStyle</item>
<item name="android:buttonStyle">@style/RobotoButtonStyle</item>
</style>
<style name="RobotoTextViewStyle" parent="android:Widget.TextView">
<item name="android:fontFamily">sans-serif-light</item>
</style>
<style name="RobotoButtonStyle" parent="android:Widget.Holo.Button">
<item name="android:fontFamily">sans-serif-light</item>
</style>
然后将主题应用于您的应用
Then Apply theme to your app
<application
android:theme="@style/AppTheme" >
</application>