为了在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; } }
解决方法
你试过这个吗?
Custom fonts in Android the easy way …@H_404_3@
这听起来很有希望.@H_404_3@