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

android – 通过资产字体更改PreferenceFragment字体,第1张

概述为了在PreferenceFragment中为每个Preference设置自定义字体,我必须为每个首选项类型(CustomSwitchPreference,CustomEditTextPreference,CustomListPreference,….)编写一个新的自定义类,并在onBindView方法中设置其字体. 它有效,但这是最好的解决方案吗?不短吗? @Overridepublic vo 为了在PreferenceFragment中为每个Preference设置自定义字体,我必须为每个首选项类型(CustomSwitchPreference,CustomEditTextPreference,CustomListPreference,….)编写一个新的自定义类,并在onBindVIEw方法中设置其字体.

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

@OverrIDepublic 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 – 通过资产字体更改PreferenceFragment字体全部内容,希望文章能够帮你解决android – 通过资产字体更改PreferenceFragment字体所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1135518.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-30
下一篇 2022-05-30

发表评论

登录后才能评论

评论列表(0条)

保存