문제

중첩된referenceScreens를 만들었습니다.사용자 정의 글꼴을 추가하고 싶습니다. 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>
도움이 되었습니까?

해결책

당신은 생성해야 CustomPreference 그리고 CustomPreferenceCategory 그에 대한.그것을 포함 CustomPreference 그리고 CustomPreferenceCategory 당신의 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);
    }
}

사용자 정의기본 카테고리:

 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 당신은 창조해야 PreferenceCategory 그리고 Preference 이러한 사용자 정의 클래스를 사용합니다.

 <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.xml 그리고 fontStyle 필요에 따라 추가하십시오.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top