Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/179.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在自定义首选项中正确读取android命名空间中的属性?_Android - Fatal编程技术网

如何在自定义首选项中正确读取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不可访问,因此我不知道如何操作。

如果您有资源引用,请稍候,您可以读取其值吗?没有?这可能就是你要找的: