2

カスタム フォントを追加したいpreferenceScreen title and summary.書体に読み込まれたフォントを使用しようとしています。これどうやってするの?ありがとう。

ここに私のpreference.xml

   <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
        <PreferenceCategory android:title="@string/manage_device_title" 
         android:key="@string/device_category">
             <PreferenceScreen android:title="@string/manage_device"
                 android:key="@string/manage_device_KEY"
                 android:summary="@string/device_summary" >     
             </PreferenceScreen>
        </PreferenceCategory>
   </PreferenceScreen>
4

1 に答える 1

6

CustomPreferenceそのためには、を作成する必要がありますCustomPreferenceCategory。それを含めてCustomPreferenceCustomPreferenceCategoryあなたのpreference.xml

カスタム設定:

public class CustomPreference extends Preference {
Typeface fontStyle;

public CustomPreference(Context context, AttributeSet attrs, int defStyle) {
    super(context, attrs, defStyle);

}

public CustomPreference(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomPreference(Context context) {
    super(context);
}

@Override
protected void onBindView(View view) {
    super.onBindView(view);

    fontStyle = Typeface.createFromAsset(CA.getApplication().getApplicationContext().getAssets(), AppConstants.fontStyle);
    TextView titleView = (TextView) view.findViewById(android.R.id.title);
    titleView.setTypeface(fontStyle);   
    titleView.setTextColor(Color.RED);
    TextView summaryView = (TextView) view.findViewById(android.R.id.summary);
    summaryView.setTypeface(fontStyle); 
    summaryView.setTextColor(Color.RED);
    }
}

CustomPreferenceCategory:

 public class CustomPreferenceCategory extends PreferenceCategory {
Typeface fontStyle;

public CustomPreferenceCategory(Context context, AttributeSet attrs,
        int defStyle) {
    super(context, attrs, defStyle);

}

public CustomPreferenceCategory(Context context, AttributeSet attrs) {
    super(context, attrs);
}

public CustomPreferenceCategory(Context context) {
    super(context);
}

@Override
protected void onBindView(View view) {
    super.onBindView(view);

    fontStyle = Typeface.createFromAsset(CA.getApplication()
            .getApplicationContext().getAssets(), AppConstants.fontStyle);
    TextView titleView = (TextView) view.findViewById(android.R.id.title);
    titleView.setTypeface(fontStyle);
    // titleView.setTextColor(Color.RED);
        }
}

これらのカスタムクラスを作成しPreference.xmlて使用する必要があります。PreferenceCategoryPreference

 <PreferenceScreen xmlns:android="http://schemas.android.com/apk/res/android">
    <CustomPreferenceCategory android:title="@string/manage_device_title" 
     android:key="@string/device_category">
         <CustomPreference android:title="@string/manage_device"
             android:key="@string/manage_device_KEY"
             android:summary="@string/device_summary" >     
         </CustomPreference>
    </CustomPreferenceCategory>
</PreferenceScreen>

注:必要に応じて参照および追加する場合は、CustomPerenceCategory および CustomPreference の適切なパッケージ名を使用してください。preference.xmlfontStyle

于 2014-02-27T06:01:17.507 に答える