当前位置:编程学习 > wap >>

TypedArray getResourceId获取不到值

整理slidingdrawer源码,打算修改源码.实现左侧的抽屉,代码部分如下:
TypedArray a = context.obtainStyledAttributes(attrs, R.styleable.SlidingDrawer, defStyle, 0);
int contentId = a.getResourceId(R.styleable.SlidingDrawer_content, 0);
        if (contentId == 0) {
            throw new IllegalArgumentException("The content attribute is required and must refer "
                    + "to a valid child.");
        }

获取不到contentId ,我还没有动任何部分代码,怎么就获取不到呢? TypedArray getResourceId --------------------编程问答-------------------- 找到错误了,是我大意了:
<com.example.drawer.SlidingDrawer 
    android:layout_width="200dp"
    android:layout_height="fill_parent"
    android:content="@+id/lin_content"
    android:handle="@+id/iv_handle12">
</com.example.drawer.SlidingDrawer>

android:content属性和android:handle属性都是系统提供的属性.不是这个组件私有的属性.修改为app:content和app:handle就可以获取到相应的值得了.如下:
<com.example.drawer.SlidingDrawer 
    android:layout_width="200dp"
    android:layout_height="fill_parent"
    app:content="@+id/lin_content"
    app:handle="@+id/iv_handle12">
</com.example.drawer.SlidingDrawer>
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,