2017-02-06 6 views
1

THIS LINKで、すべての設定の書体をPreferenceScreenに変更しようとしました。 ListPreferenceの要約を除いてどこでも変更されました。 ListPreferenceの要約にカスタムフォントを適用する方法を知っている人はいますか?私は私のカスタムフォントを適用したい`ListPreference`の要約のフォントの書体を変更してください

UPDATE

は、資産フォルダ、いないでビルド1上に存在します。またandroid:textAppearanceListItemSecondary API 21を必要と、私のアプリのサポート最小API 15.

答えて

0

は最後にListPreferenceの概要については、フォントを変更する方法をこの

<!-- 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

を試してみてください。

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

他にもこのヘルプが必要です。

関連する問題