Android: Custom Xml Attributes for PreferenceScreen
I use custom xml attributes for preferences. The preferences are inflated from xml.
I managed to create and read custom xml attributes for EditTextPreference, ListPreference and CheckBoxPreference by creating custom classes which inherit from the respective preference class.
In the constructor of the class I can read the attributes like so:
public class CustomTextPreference extends EditTextPreference {
public CustomTextPreference(Context context, AttributeSet attrs) {
super(context, a开发者_运维技巧ttrs);
TypedArray a = context.obtainStyledAttributes(attrs,R.styleable.PreferenceCustomAttrs);
x = a.getString(R.styleable.PreferenceCustomAttrs_x);
y = a.getString(R.styleable.PreferenceCustomAttrs_y);
}
}
My problem is that I can't do this for the PreferenceScreen class, as it is a final class. So my question is: Is there any way I can read the custom attributes of a PreferenceScreen?
Probably not by the same techniques that you are using. Remember, though, that preference XML files are just XML resources. You can get a parser for the file via getResources().getXml()
from your PreferenceActivity
. From there, you can read whatever you want.
精彩评论