Android Can';无法在XML中加载自定义属性
我试着了解如何为自定义视图的布局XML创建自定义属性,但是无论我做什么,我都会得到一个零自定义属性的列表,并且我很难弄清楚如何调试它 我创建了一个文件res/values/attrs.xml,如下所示:Android Can';无法在XML中加载自定义属性,android,Android,我试着了解如何为自定义视图的布局XML创建自定义属性,但是无论我做什么,我都会得到一个零自定义属性的列表,并且我很难弄清楚如何调试它 我创建了一个文件res/values/attrs.xml,如下所示: <?xml version="1.0" encoding="utf-8"?> <resources> <declare-styleable name="TexturedListView"> <attr name="backgrou
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="TexturedListView">
<attr name="backgroundTexture" format="reference"/>
</declare-styleable>
</resources>
然而,毫无疑问,N是0。R.styleable.TexturedListView中似乎有正确的ID,我尝试过清理和重建我的项目,但没有效果。我觉得我必须错过一些微妙的东西,但我无法理解
我做错了什么?如何读取这些自定义属性
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="https://schemas.android.com/apk/res/xxx.rtin.texturedlistview"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<xxx.rtin.texturedlistview.TexturedListView
android:id="@+id/texturedListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:dividerHeight="10dp"
android:padding="20dp"
custom:backgroundTexture="@drawable/background" >
</xxx.rtin.texturedlistview.TexturedListView>
</RelativeLayout>
public TexturedListView(Context context, AttributeSet attrs) {
super(context, attrs);
TypedArray a = context.obtainStyledAttributes(R.styleable.TexturedListView);
final int N = a.getIndexCount();
//..snip...
}