Наконец путь, чтобы изменить шрифт для резюме ListPreference
.
Переопределите метод onBindViewHolder
ListPreference
, чтобы установить свой собственный шрифт. Проверьте ниже пользовательский класс.
public class CustomListPreference extends ListPreference {
private String typefaceTitle, typefaceSummary;
public CustomListPreference(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init(context, attrs);
}
public CustomListPreference(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
public CustomListPreference(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public CustomListPreference(Context context) {
super(context);
}
@Override
public void onBindViewHolder(PreferenceViewHolder holder) {
super.onBindViewHolder(holder);
if(!TextUtils.isEmpty(typefaceTitle)) {
TextView titleView = (TextView) holder.findViewById(android.R.id.title);
titleView.setTypeface(FontManager.getInstance().getFont(typefaceTitle));
}
if(!TextUtils.isEmpty(typefaceSummary)){
final TextView summaryView = (TextView) holder.findViewById(
android.R.id.summary);
summaryView.setTypeface(FontManager.getInstance().getFont(typefaceSummary));
}
}
private void init(Context context, AttributeSet attrs){
TypedArray a = context.obtainStyledAttributes(attrs,
R.styleable.Preference);
typefaceTitle = a.getString(R.styleable.Preference_typefaceTitle);
typefaceSummary = a.getString(R.styleable.Preference_typefaceSummary);
a.recycle();
}}
attrs.xml
<declare-styleable name="Preference">
<attr name="typefaceTitle" format="string"></attr>
<attr name="typefaceSummary" format="string"></attr>
</declare-styleable>
Использование в экране предпочтений.
<YOUR_CustomListPreference_PACKAGE_NAME.CustomListPreference
android:defaultValue="X"
android:dialogTitle="Dialog Title"
android:entries="@array/list_item_title"
android:entryValues="@array/list_item_value"
android:key="pref_list"
android:summary="%s"
android:title="@string/Preference Title"
app:typefaceTitle="YOUR FONT NAME"
app:typefaceSummary="YOUR FONT NAME"/>
Надеюсь, что эта помощь для других.