为了在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 …
这听起来很有希望.