設定にはカスタム xml 属性を使用します。設定は xml からインフレートされます。
それぞれの設定クラスから継承するカスタム クラスを作成することで、EditTextPreference、ListPreference、および CheckBoxPreference のカスタム xml 属性を作成して読み取ることができました。
クラスのコンストラクターでは、次のように属性を読み取ることができます。
public class CustomTextPreference extends EditTextPreference {
public CustomTextPreference(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.PreferenceCustomAttrs);
x = a.getString(R.styleable.PreferenceCustomAttrs_x);
y = a.getString(R.styleable.PreferenceCustomAttrs_y);
}
}
私の問題は、最終クラスであるため、PreferenceScreen クラスに対してこれを行うことができないことです。だから私の質問は: PreferenceScreen のカスタム属性を読み取る方法はありますか?