我使用自定义 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 的自定义属性?