如何在自定义首选项中正确读取android命名空间中的属性?
我正在编写一个自定义的如何在自定义首选项中正确读取android命名空间中的属性?,android,Android,我正在编写一个自定义的首选项。我可以轻松读取私有命名空间中的属性值: public MyPreference(Context context, AttributeSet attrs) { super(context, attrs); TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MyPreference); mDefaultValue = styledAttrs.get
首选项
。我可以轻松读取私有命名空间中的属性值:
public MyPreference(Context context, AttributeSet attrs)
{
super(context, attrs);
TypedArray styledAttrs = context.obtainStyledAttributes(attrs, R.styleable.MyPreference);
mDefaultValue = styledAttrs.getInt(R.styleable.MyPreference_defaultValue, 0);
}
但我不知道如何读取android属性,例如,
android:defaultValue
。在web上的所有示例中,属性都包含值,但我使用了@integer/my_number
等资源,因此简单地读取attrs
不起作用-属性包含资源引用,但不包含值。android.R.styleable不可访问,因此我不知道如何操作。如果您有资源引用,请稍候,您可以读取其值吗?没有?这可能就是你要找的: