당신은 그것에 대해 CustomPreference
및 CustomPreferenceCategory
을 작성해야합니다. 포함하여 preference.xml
CustomPreference에서 CustomPreference
및 CustomPreferenceCategory
그 :
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
당신이 사용자 정의 클래스와 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>
참고 : preference.xml
에 refereing 때 CustomPerenceCategory 및 CustomPreference의 적절한 패키지 이름을 사용하고 fontStyle
의 필요성에 따라 추가하십시오.
답변 해 주셔서 감사합니다. 미안 해요, 내 preferenceScreen.addPreference() 함수를 사용하여 자식 preferenceScreen에 환경 설정을 추가했다는 것을 알립니다. CustomPreference를 사용할 때이 메서드를 사용할 수 없습니다. 그래서 하위 화면에 환경 설정을 추가 할 수 없습니다. 그래서 내가 무엇을해야하니? –
@KelumDeshapriya :'addPreferencesFromResource (R.xml.preference)'를 사용하고 있지 않습니까? –
예. 나는 그것을 사용한다. 하지만 난 또한 addPreference() 프로그램에서 자식 preferenceScreen 내 동적 환경 설정 목록을 추가 할 수 있습니다. –