【发布时间】:2010-09-26 19:15:51
【问题描述】:
我使用自定义 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 的自定义属性?
【问题讨论】:
标签: android android-preferences