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

前端之家收集整理的这篇文章主要介绍了android – 通过资产字体更改PreferenceFragment字体前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
为了在PreferenceFragment中为每个Preference设置自定义字体,我必须为每个首选项类型(CustomSwitchPreference,CustomEditTextPreference,CustomListPreference,….)编写一个新的自定义类,并在onBindView方法中设置其字体.

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

  1. @Override
  2. public void onBindView(View view){
  3. super.onBindView(view);
  4. TextView title = (TextView) view.findViewById(android.R.id.title);
  5. TextView summary = (TextView) view.findViewById(android.R.id.summary);
  6. Utils.setFont(context,title,customfont);
  7. Utils.setFont(context,summary,customfont);
  8. }
  9.  
  10. public class Utils{
  11. public static boolean setFont(Context context,TextView tv,String fontAssetName) {
  12. Typeface font = Typeface.createFromAsset(context.getResources().getAssets(),fontAssetName);
  13. if (font != null) {
  14. tv.setTypeface(font);
  15. return true;
  16. }
  17. return false;
  18. }
  19. }

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

解决方法

你试过这个吗?

Custom fonts in Android the easy way …

这听起来很有希望.

猜你在找的Android相关文章