2017-02-06 7 views
1

Я пробовал с THIS LINK, чтобы изменить шрифт всех настроек PreferenceScreen. Это было изменено повсюду, кроме резюме ListPreference. Может кто-нибудь есть идея, как применить пользовательский шрифт в сводке ListPreference?Изменить шрифт шрифт резюме `ListPreference`

UPDATE

Я хочу, чтобы применить свой собственный шрифт существует на папке активов, а не в-построить. Также android:textAppearanceListItemSecondary требуется API 21, мое приложение поддержки минимум API 15.

ответ

0

попробовать этот

<!-- Base application theme. --> 
    <style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar"> 
     <!-- Customize your theme here. --> 
     <item name="android:textAppearanceListItemSecondary">@style/textAppearanceListItemSecondaryCustom</item> 
    </style> 


    <style name="textAppearanceListItemSecondaryCustom"> 
     <item name="android:textSize">14sp</item> 
     <item name="android:typeface">monospace</item> 
    </style> 
0

Наконец путь, чтобы изменить шрифт для резюме ListPreference.

Переопределите метод onBindViewHolderListPreference, чтобы установить свой собственный шрифт. Проверьте ниже пользовательский класс.

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"/> 

Надеюсь, что эта помощь для других.

Смежные вопросы