android – 通过资产字体更改PreferenceFragment字体

为了在PreferenceFragment中为每个Preference设置自定义字体,我必须为每个首选项类型(CustomSwitchPreference,CustomEditTextPreference,CustomListPreference,….)编写一个新的自定义类,并在onBindView方法中设置其字体.

它有效,但这是最好的解决方案吗?不短吗?

@Override
public void onBindView(View view){
    super.onBindView(view);
    TextView title = (TextView) view.findViewById(android.R.id.title);
    TextView summary = (TextView) view.findViewById(android.R.id.summary);
    Utils.setFont(context,title,customfont);
    Utils.setFont(context,summary,customfont);
}

public class Utils{
    public static boolean setFont(Context context,TextView tv,String fontAssetName) {
        Typeface font = Typeface.createFromAsset(context.getResources().getAssets(),fontAssetName);
        if (font != null) {
            tv.setTypeface(font);
            return true;
        }
        return false;
    }
}

有没有办法更改PreferenceFragment的所有片段的字体,包括对话框?

解决方法

你试过这个吗?

Custom fonts in Android the easy way …

这听起来很有希望.

相关文章

Android性能优化——之控件的优化 前面讲了图像的优化,接下...
前言 上一篇已经讲了如何实现textView中粗字体效果,里面主要...
最近项目重构,涉及到了数据库和文件下载,发现GreenDao这个...
WebView加载页面的两种方式 一、加载网络页面 加载网络页面,...
给APP全局设置字体主要分为两个方面来介绍 一、给原生界面设...
前言 最近UI大牛出了一版新的效果图,按照IOS的效果做的,页...