android - 为完整的 android 应用程序添加自定义字体

标签 android textview custom-font

在我的应用程序中,我需要对所有 TextView 和编辑文本字段使用 helvetica 字体。除了对每个 textview 使用 settypeface 方法之外,还有什么方法可以做到这一点?任何建议都会有很大帮助。

提前致谢!

最佳答案

我自己想通了。这是我使用的代码。我创建自定义 TextView 自定义字体作为默认字体。

public class MyTextView extends TextView {

    public MyTextView(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    public MyTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
    }

    public MyTextView(Context context) {
        super(context);
        init();
    }

    private void init() {
        Typeface tf = Typeface.createFromAsset(getContext().getAssets(), "font/chiller.ttf");
        setTypeface(tf ,1);

    }

}

关于android - 为完整的 android 应用程序添加自定义字体,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6926263/

相关文章:

android - 拆分一个字符串,使文本在彼此之下

android - 更改 Android 模拟器大小以适合我的屏幕

java - ListView Filter 过滤正确但显示错误结果

Android:以编程方式在 EditText 中居中文本

android - 在 android 文本切换器或 View 翻转器中将大文本分成页面

ios - 如何防止键盘在 TextView 上显示(而不是关闭)?

php - DOMPDF 的自定义字体

css - 自定义字体为空白并在加载时出现

xamarin.ios - 使用 ShowText 时自定义字体无法正确呈现

android - 更新后允许按钮不起作用