【发布时间】:2013-12-11 10:47:52
【问题描述】:
为了在 PreferenceFragment 中为每个偏好设置自定义字体,我必须为 每个 偏好类型(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 包括对话框的所有段的字体?
【问题讨论】:
标签: android android-fragments customization android-preferences