【问题标题】:Changing all typefaces of an android application [duplicate]更改android应用程序的所有字体[重复]
【发布时间】:2015-09-22 00:04:22
【问题描述】:

如何更改我的 android 应用程序的整个字体? 之前我在 github 上看到了this post。该解决方案仅适用于低于 api 21 的设备。 对于 android 5,即使我们单独添加带有 styles.xmlvalues-v21 文件夹,此方法也不起作用。

这是我的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>

【问题讨论】:

标签: android styles typeface android-5.1.1-lollipop


【解决方案1】:
<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>

然后将主题应用到您的应用

<application
    android:theme="@style/AppTheme" >
</application>

【讨论】:

  • 对我不起作用。顺便说一句,似乎只有文本视图和按钮会因此而改变。我想将整个应用程序字体更改为我的自定义字体之一
  • Look at this 他们正在尝试做某事。加入他们
【解决方案2】:

一个建议是创建扩展 android TextView 的自定义 Textview。我在下面包含示例代码

public class CustomTextView extends TextView{

public CustomTextView(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    // TODO Auto-generated constructor stub
}
public CustomTextView(Context context) {
    super(context);
    init();
    // TODO Auto-generated constructor stub
}
public CustomTextView(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);
    init();
    // TODO Auto-generated constructor stub
}
private void init(){
    Typeface font_type=Typeface.createFromAsset(getContext().getAssets(), "font/ProximaNova_Reg.ttf");
    setTypeface(font_type);
}

}

把你的字体放在android资产/字体文件夹中。你可以为Button、EditText等做。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2015-01-03
    • 1970-01-01
    • 2016-02-25
    • 2021-07-11
    • 1970-01-01
    相关资源
    最近更新 更多