最简单的在全球范围内改变Android的字体的方法吗? [英] Easiest way to globally change Android font?

查看:97
本文介绍了最简单的在全球范围内改变Android的字体的方法吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个TTF文件,其理论上是可行的,但我并不想触及了500个不同的线路code编程改变这种情况。什么是最简单的方法是什么?

I have a ttf file, and its theoretically possible, but I'm not looking to touch over 500 different lines of code to programmatically change this. What is the easiest way?

<一个href="http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Typefaces.html" rel="nofollow">http://developer.android.com/resources/samples/ApiDemos/src/com/example/android/apis/graphics/Typefaces.html

推荐答案

要延长 previous 静态回答字体:

添加新功能:

public static void applyCustomFont(ViewGroup list, Typeface customTypeface) {
            for (int i = 0; i < list.getChildCount(); i++) {
                View view = list.getChildAt(i);
                if (view instanceof ViewGroup) {
                    applyCustomFont((ViewGroup) view, customTypeface);
                } else if (view instanceof TextView) {
                    ((TextView) view).setTypeface(customTypeface);
                }
            }
        }

获取我们的布局的根视图:

Get root view of our Layout:

View rootView = findViewById(android.R.id.content)

比所有的子元素应用自定义的字体为整个活动形式:

Than apply custom font for whole activity form with all sub-elements:

applyCustomFont((ViewGroup)rootView, C.TYPEFACE.ArialRounded(this));

这篇关于最简单的在全球范围内改变Android的字体的方法吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆